A color represented in RGBA format by a red (r), green (g), blue (b), and alpha (a) component. Each component is a 32-bit floating-point value, usually ranging from 0.0
to 1.0
. Some properties (such as CanvasItem.modulate) may support values greater than 1.0
, for overbright or HDR (High Dynamic Range) colors.
Colors can be created in various ways: By the various Color constructors, by static methods such as from_hsv, and by using a name from the set of standardized colors based on X11 color names with the addition of TRANSPARENT. GDScript also provides @GDScript.Color8, which uses integers from 0
to 255
and doesn't support overbright colors.
Constructs a default Color from opaque black. This is the same as BLACK.
Note: in C#, constructs an empty color with all of its components set to 0.0
(transparent black).
Constructs a Color from the existing color, with a set to the given alpha
value.
Constructs a Color as a copy of the given Color.
Constructs a Color either from an HTML color code or from a standardized color name. The supported color names are the same as the constants.
Constructs a Color either from an HTML color code or from a standardized color name, with alpha
on the range of 0.0 to 1.0. The supported color names are the same as the constants.
Constructs a Color from RGB values, typically between 0.0 and 1.0. a is set to 1.0.
Constructs a Color from RGBA values, typically between 0.0 and 1.0.
Returns true
if the colors are not exactly equal.
Note: Due to floating-point precision errors, consider using is_equal_approx instead, which is more reliable.
Multiplies each component of the Color by the components of the given Color.
Multiplies each component of the Color by the given float.
Multiplies each component of the Color by the given int.
Adds each component of the Color with the components of the given Color.
Subtracts each component of the Color by the components of the given Color.
Divides each component of the Color by the components of the given Color.
Divides each component of the Color by the given float.
Divides each component of the Color by the given int.
Returns true
if the colors are exactly equal.
Note: Due to floating-point precision errors, consider using is_equal_approx instead, which is more reliable.
Access color components using their index. [0]
is equivalent to r, [1]
is equivalent to g, [2]
is equivalent to b, and [3]
is equivalent to a.
Returns the same value as if the +
was not there. Unary +
does nothing, but sometimes it can make your code more readable.
Inverts the given color. This is equivalent to Color.WHITE - c
or Color(1 - c.r, 1 - c.g, 1 - c.b, 1 - c.a)
. Unlike with inverted, the a component is inverted, too.
The color's alpha component, typically on the range of 0 to 1. A value of 0 means that the color is fully transparent. A value of 1 means that the color is fully opaque.
Wrapper for a that uses the range 0 to 255, instead of 0 to 1.
The color's blue component, typically on the range of 0 to 1.
Wrapper for b that uses the range 0 to 255, instead of 0 to 1.
The color's green component, typically on the range of 0 to 1.
Wrapper for g that uses the range 0 to 255, instead of 0 to 1.
The HSV hue of this color, on the range 0 to 1.
The color's red component, typically on the range of 0 to 1.
Wrapper for r that uses the range 0 to 255, instead of 0 to 1.
The HSV saturation of this color, on the range 0 to 1.
The HSV value (brightness) of this color, on the range 0 to 1.
Returns a new color resulting from overlaying this color over the given color. In a painting program, you can imagine it as the over
color painted over this color (including alpha).
Returns a new color with all components clamped between the components of min
and max
, by running @GlobalScope.clamp on each component.
Returns a new color resulting from making this color darker by the specified amount
(ratio from 0.0 to 1.0). See also lightened.
Constructs a color from an HSV profile. The hue (h
), saturation (s
), and value (v
) are typically between 0.0 and 1.0.
Constructs a color from an OK HSL profile. The hue (h
), saturation (s
), and lightness (l
) are typically between 0.0 and 1.0.
Decodes a Color from a RGBE9995 format integer. See Image.FORMAT_RGBE9995.
Creates a Color from the given string, which can be either an HTML color code or a named color (case-insensitive). Returns default
if the color cannot be inferred from the string.
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: get_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 srgb_to_linear to convert it to the linear color space first.
Returns the Color associated with the provided hex
integer in 32-bit RGBA format (8 bits per channel).
In GDScript and C#, the int is best visualized with hexadecimal notation ("0x"
prefix, making it "0xRRGGBBAA"
).
Returns the Color associated with the provided hex
integer in 64-bit RGBA format (16 bits per channel).
In GDScript and C#, the int is best visualized with hexadecimal notation ("0x"
prefix, making it "0xRRRRGGGGBBBBAAAA"
).
Returns a new color from rgba
, an HTML hexadecimal color string. rgba
is not case-sensitive, and may be prefixed by a hash sign (#
).
rgba
must be a valid three-digit or six-digit hexadecimal color string, and may contain an alpha channel value. If rgba
does not contain an alpha channel value, an alpha channel value of 1.0 is applied. If rgba
is invalid, returns an empty color.
Returns true
if color
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 String.is_valid_html_color.
Returns the color with its r, g, and b components inverted ((1 - r, 1 - g, 1 - b, a)
).
Returns true
if this color and to
are approximately equal, by running @GlobalScope.is_equal_approx on each component.
Returns the linear interpolation between this color's components and to
's components. The interpolation factor weight
should be between 0.0 and 1.0 (inclusive). See also @GlobalScope.lerp.
Returns a new color resulting from making this color lighter by the specified amount
, which should be a ratio from 0.0 to 1.0. See also darkened.
Returns the color converted to the sRGB color space. This method assumes the original color is in the linear color space. See also srgb_to_linear which performs the opposite operation.
Returns the color converted to the linear color space. This method assumes the original color already is in the sRGB color space. See also linear_to_srgb which performs the opposite operation.
Returns the color converted to a 32-bit integer in ABGR format (each component is 8 bits). ABGR is the reversed version of the default RGBA format.
Returns the color converted to a 64-bit integer in ABGR format (each component is 16 bits). ABGR is the reversed version of the default RGBA format.
Returns the color converted to a 32-bit integer in ARGB format (each component is 8 bits). ARGB is more compatible with DirectX.
Returns the color converted to a 64-bit integer in ARGB format (each component is 16 bits). ARGB is more compatible with DirectX.
Returns the color converted to an HTML hexadecimal color String in RGBA format, without the hash (#
) prefix.
Setting with_alpha
to false
, excludes alpha from the hexadecimal string, using RGB format instead of RGBA format.
Returns the color converted to a 32-bit integer in RGBA format (each component is 8 bits). RGBA is Godot's default format.
Returns the color converted to a 64-bit integer in RGBA format (each component is 16 bits). RGBA is Godot's default format.