A color represented in RGBA format.
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 a number of 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.
Although Color may be used to store values of any encoding, the red (r), green (g), and blue (b) properties of Color are expected by Godot to be encoded using the nonlinear sRGB transfer function unless otherwise stated. This color encoding is used by many traditional art and web tools, making it easy to match colors between Godot and these tools. Godot uses Rec. ITU-R BT.709 color primaries, which are used by the sRGB standard.
All physical simulation, such as lighting calculations, and colorimetry transformations, such as get_luminance(), must be performed on linearly encoded values to produce correct results. When performing these calculations, convert Color to and from linear encoding using srgb_to_linear() and linear_to_srgb().
Note: In a boolean context, a Color will evaluate to false if it is equal to Color(0, 0, 0, 1) (opaque black). Otherwise, a Color will always evaluate to true.
Note: In C#, color constants are defined in the Colors static class instead of [code skip-lint]Color[/code]. Additionally, named colors use PascalCase syntax instead of UPPER_SNAKE_CASE. For example, [code skip-lint]Color.ALICE_BLUE[/code] in GDScript is [code skip-lint]Colors.AliceBlue[/code] in C#.
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.
Note: The alpha channel is always stored with linear encoding, regardless of the encoding of the other color channels. The linear_to_srgb() and srgb_to_linear() methods do not affect the alpha channel.
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).
var bg = Color(0.0, 1.0, 0.0, 0.5) # Green with alpha of 50%
var fg = Color(1.0, 0.0, 0.0, 0.5) # Red with alpha of 50%
var blended_color = bg.blend(fg) # Brown with alpha of 75%Returns a new color with all components clamped between the components of min and max, by running 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().
var green = Color(0.0, 1.0, 0.0)
var darkgreen = green.darkened(0.2) # 20% darker than regular greenConstructs a color from an HSV profile. The hue (h), saturation (s), and value (v) are typically between 0.0 and 1.0.
var color = Color.from_hsv(0.58, 0.5, 0.79, 0.8)Constructs a color from an OK HSL profile. The hue (h), saturation (s), and lightness (l) are typically between 0.0 and 1.0.
var color = Color.from_ok_hsl(0.58, 0.5, 0.79, 0.8)Returns a Color constructed from red (r8), green (g8), blue (b8), and optionally alpha (a8) integer channels, each divided by 255.0 for their final value.
var red = Color.from_rgba8(255, 0, 0) # Same as Color(1, 0, 0).
var dark_blue = Color.from_rgba8(0, 0, 51) # Same as Color(0, 0, 0.2).
var my_color = Color.from_rgba8(306, 255, 0, 102) # Same as Color(1.2, 1, 0, 0.4).Note: Due to the lower precision of from_rgba8() compared to the standard Color constructor, a color created with from_rgba8() will generally not be equal to the same color created with the standard Color constructor. Use is_equal_approx() for comparisons to avoid issues with floating-point precision error.
Decodes a Color from an 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.
If you want to create a color from String in a constant expression, use the equivalent constructor instead (i.e. Color("color 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 using linear encoding to return an accurate relative luminance value. If the color uses the default nonlinear sRGB encoding, use srgb_to_linear() to convert it to linear encoding first.
Returns the Color associated with the provided hex integer in 32-bit RGBA format (8 bits per channel). This method is the inverse of to_rgba32().
In GDScript and C#, the int is best visualized with hexadecimal notation ("0x" prefix, making it "0xRRGGBBAA").
var red = Color.hex(0xff0000ff)
var dark_cyan = Color.hex(0x008b8bff)
var my_color = Color.hex(0xbbefd2a4)If you want to use hex notation in a constant expression, use the equivalent constructor instead (i.e. Color(0xRRGGBBAA)).
Returns the Color associated with the provided hex integer in 64-bit RGBA format (16 bits per channel). This method is the inverse of to_rgba64().
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.
var blue = Color.html("#0000ff") # blue is Color(0.0, 0.0, 1.0, 1.0)
var green = Color.html("#0F0") # green is Color(0.0, 1.0, 0.0, 1.0)
var col = Color.html("663399cc") # col is Color(0.4, 0.2, 0.6, 0.8)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().
Color.html_is_valid("#55aaFF") # Returns true
Color.html_is_valid("#55AAFF20") # Returns true
Color.html_is_valid("55AAFF") # Returns true
Color.html_is_valid("#F2C") # Returns true
Color.html_is_valid("#AABBC") # Returns false
Color.html_is_valid("#55aaFF5") # Returns falseReturns true if this color and to are approximately equal, by running 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 lerp().
var red = Color(1.0, 0.0, 0.0)
var aqua = Color(0.0, 1.0, 0.8)
red.lerp(aqua, 0.2) # Returns Color(0.8, 0.2, 0.16)
red.lerp(aqua, 0.5) # Returns Color(0.5, 0.5, 0.4)
red.lerp(aqua, 1.0) # Returns Color(0.0, 1.0, 0.8)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().
var green = Color(0.0, 1.0, 0.0)
var light_green = green.lightened(0.2) # 20% lighter than regular greenReturns a copy of the color that is encoded using the nonlinear sRGB transfer function. This method requires the original color to use linear encoding. See also srgb_to_linear() which performs the opposite operation.
Note: The color's alpha channel (a) is not affected. The alpha channel is always stored with linear encoding, regardless of the color space of the other color channels.
Returns a copy of the color that uses linear encoding. This method requires the original color to be encoded using the nonlinear sRGB transfer function. See also linear_to_srgb() which performs the opposite operation.
Note: The color's alpha channel (a) is not affected. The alpha channel is always stored with linear encoding, regardless of the color space of the other color channels.
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.
var color = Color(1, 0.5, 0.2)
print(color.to_abgr32()) # Prints 4281565439Returns 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.
var color = Color(1, 0.5, 0.2)
print(color.to_abgr64()) # Prints -225178692812801Returns the color converted to a 32-bit integer in ARGB format (each component is 8 bits). ARGB is more compatible with DirectX.
var color = Color(1, 0.5, 0.2)
print(color.to_argb32()) # Prints 4294934323Returns the color converted to a 64-bit integer in ARGB format (each component is 16 bits). ARGB is more compatible with DirectX.
var color = Color(1, 0.5, 0.2)
print(color.to_argb64()) # Prints -2147470541Returns 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.
var white = Color(1, 1, 1, 0.5)
var with_alpha = white.to_html() # Returns "ffffff7f"
var without_alpha = white.to_html(false) # Returns "ffffff"Returns the color converted to a 32-bit integer in RGBA format (each component is 8 bits). RGBA is Godot's default format. This method is the inverse of hex().
var color = Color(1, 0.5, 0.2)
print(color.to_rgba32()) # Prints 4286526463Returns the color converted to a 64-bit integer in RGBA format (each component is 16 bits). RGBA is Godot's default format. This method is the inverse of hex64().
var color = Color(1, 0.5, 0.2)
print(color.to_rgba64()) # Prints -140736629309441