(code of this item is picked from Godot Engine in compliance with MIT license).
A color represented by red, green, blue, and alpha (RGBA) components.
The alpha component is often used for transparency.
Values are in floating-point and usually range from 0 to 1.
Some properties (such as
CanvasItem.Modulate
) may accept values
greater than 1 (overbright or HDR colors).
If you want to supply values in a range of 0 to 255, you should use
Color8
and the
r8
/
g8
/
b8
/
a8
properties.
Constructs a Color from an existing color and an alpha value.
( uint rgba )
Constructs a Color from an unsigned 32-bit integer in RGBA format (each byte represents a color channel).
( ulong rgba )
Constructs a Color from an unsigned 64-bit integer in RGBA format (each word represents a color channel).
( string code )
Constructs a Color either from an HTML color code or from a standardized color name. Supported color names are the same as the Colors constants.
( string code, float alpha )
Constructs a Color either from an HTML color code or from a standardized color name, with name on the range of 0 to 1. Supported color names are the same as the Colors constants.
Wrapper for R that uses the range 0 to 255 instead of 0 to 1. Getting is equivalent to multiplying by 255 and rounding. Setting is equivalent to dividing by 255.
G8
byte
get / set
Wrapper for G that uses the range 0 to 255 instead of 0 to 1. Getting is equivalent to multiplying by 255 and rounding. Setting is equivalent to dividing by 255.
B8
byte
get / set
Wrapper for B that uses the range 0 to 255 instead of 0 to 1. Getting is equivalent to multiplying by 255 and rounding. Setting is equivalent to dividing by 255.
A8
byte
get / set
Wrapper for A that uses the range 0 to 255 instead of 0 to 1. Getting is equivalent to multiplying by 255 and rounding. Setting is equivalent to dividing by 255.
H
float
get / set
The HSV hue of this color, on the range 0 to 1. Getting is a long process, refer to the source code for details. Setting uses FromHsv .
S
float
get / set
The HSV saturation of this color, on the range 0 to 1. Getting is equivalent to the ratio between the min and max RGB value. Setting uses FromHsv .
V
float
get / set
The HSV value (brightness) of this color, on the range 0 to 1. Getting is equivalent to using Math.Max(float, float) on the RGB components. Setting uses FromHsv .
Luminance
float
get
Returns the light intensity of the color, as a value between 0.0 and 1.0 (inclusive). This is useful when determining light or dark color. Colors with a luminance smaller than 0.5 can be generally considered dark. Note: Luminance relies on the color being in the linear color space to return an accurate relative luminance value. If the color is in the sRGB color space use SrgbToLinear to convert it to the linear color space first.
Returns a new color resulting from blending this color over another. If the color is opaque, the result is also opaque. The second color may have a range of alpha values.
Returns the color converted to the sRGB color space. This method assumes the original color is in the linear color space. See also SrgbToLinear which performs the opposite operation.
Returns the color converted to linear color space. This method assumes the original color already is in sRGB color space. See also LinearToSrgb which performs the opposite operation.
uint
ToAbgr32 ( )
Returns the color converted to an unsigned 32-bit integer in ABGR format (each byte represents a color channel). ABGR is the reversed version of the default format.
ulong
ToAbgr64 ( )
Returns the color converted to an unsigned 64-bit integer in ABGR format (each word represents a color channel). ABGR is the reversed version of the default format.
uint
ToArgb32 ( )
Returns the color converted to an unsigned 32-bit integer in ARGB format (each byte represents a color channel). ARGB is more compatible with DirectX, but not used much in Godot.
ulong
ToArgb64 ( )
Returns the color converted to an unsigned 64-bit integer in ARGB format (each word represents a color channel). ARGB is more compatible with DirectX, but not used much in Godot.
uint
ToRgba32 ( )
Returns the color converted to an unsigned 32-bit integer in RGBA format (each byte represents a color channel). RGBA is Godot's default and recommended format.
ulong
ToRgba64 ( )
Returns the color converted to an unsigned 64-bit integer in RGBA format (each word represents a color channel). RGBA is Godot's default and recommended format.
string
ToHtml ( bool includeAlpha )
Returns the color's HTML hexadecimal color string in RGBA format.
void
ToHsv ( float hue, float saturation, float value )
Converts a color to HSV values. This is equivalent to using each of the h / s / v properties, but much more efficient.
Returns true if the colors are exactly equal. Note: Due to floating-point precision errors, consider using IsEqualApprox instead, which is more reliable.
Constructs a color from the given string, which can be either an HTML color code or a named color. Returns name if the color cannot be inferred from the string. Supported color names are the same as the Colors constants.
bool
HtmlIsValid ( ReadOnlySpan color )
Returns true if name is a valid HTML hexadecimal color string. The string must be a hexadecimal value (case-insensitive) of either 3, 4, 6 or 8 digits, and may be prefixed by a hash sign ( # ). This method is identical to StringExtensions.IsValidHtmlColor(string) .
Returns true if the colors are exactly equal. Note: Due to floating-point precision errors, consider using IsEqualApprox instead, which is more reliable.
Compares two Color s by first checking if the red value of the name color is less than the red value of the name color. If the red values are exactly equal, then it repeats this check with the green values of the two colors, then with the blue values, and then with the alpha value. This operator is useful for sorting colors.
Compares two Color s by first checking if the red value of the name color is greater than the red value of the name color. If the red values are exactly equal, then it repeats this check with the green values of the two colors, then with the blue values, and then with the alpha value. This operator is useful for sorting colors.
Compares two Color s by first checking if the red value of the name color is less than or equal to the red value of the name color. If the red values are exactly equal, then it repeats this check with the green values of the two colors, then with the blue values, and then with the alpha value. This operator is useful for sorting colors.
Compares two Color s by first checking if the red value of the name color is greater than or equal to the red value of the name color. If the red values are exactly equal, then it repeats this check with the green values of the two colors, then with the blue values, and then with the alpha value. This operator is useful for sorting colors.