Color built-in type, in RGBA format.
A color represented in RGBA format by red ([member r]), green ([member g]), blue ([member b]), and alpha ([member a]) components. Each component is a 16-bit floating-point value, usually ranging from 0 to 1. Some properties (such as [member CanvasItem.modulate]) may support values greater than 1, for overbright or High Dynamic Range colors. If you want to supply values in a range of 0 to 255, you should use [method @GDScript.Color8].
Colors can also be created by name from a set of standardized colors, through the [String] constructor, [method from_string], or by directly fetching the color constants documented here. The standardized color set is based on the [url=https://en.wikipedia.org/wiki/X11_color_names]X11 color names[/url], with the addition of [constant TRANSPARENT].
[b]Note:[/b] In a boolean context, a Color will evaluate to [code]false[/code] if it's equal to [code]Color(0, 0, 0, 1)[/code] (opaque black). Otherwise, a Color will always evaluate to [code]true[/code].
[url=https://raw.githubusercontent.com/godotengine/godot-docs/master/img/color_constants.png]Color constants cheatsheet[/url]
https://godotengine.org/asset-library/asset/517
https://godotengine.org/asset-library/asset/146
https://godotengine.org/asset-library/asset/133
Constructs a default [Color] from opaque black. This is the same as [constant BLACK].
[b]Note:[/b] in C#, constructs an empty color with all of its components set to [code]0.0[/code] (transparent black).
Constructs a [Color] from the existing color, with [member a] set to the given [param alpha] value.
[codeblocks]
[gdscript]
var red = Color(Color.RED, 0.2) # 20% opaque red.
[/gdscript]
[csharp]
var red = new Color(Colors.Red, 0.2f); // 20% opaque red.
[/csharp]
[/codeblocks]
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 [param 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. [member a] is set to 1.0.
[codeblocks]
[gdscript]
var color = Color(0.2, 1.0, 0.7) # Similar to `Color8(51, 255, 178, 255)`
[/gdscript]
[csharp]
var color = new Color(0.2f, 1.0f, 0.7f); // Similar to `Color.Color8(51, 255, 178, 255)`
[/csharp]
[/codeblocks]
Constructs a [Color] from RGBA values, typically between 0.0 and 1.0.
[codeblocks]
[gdscript]
var color = Color(0.2, 1.0, 0.7, 0.8) # Similar to `Color8(51, 255, 178, 204)`
[/gdscript]
[csharp]
var color = new Color(0.2f, 1.0f, 0.7f, 0.8f); // Similar to `Color.Color8(51, 255, 178, 255, 204)`
[/csharp]
[/codeblocks]
Returns a new color resulting from overlaying this color over the given color. In a painting program, you can imagine it as the [param over] color painted over this color (including alpha).
[codeblocks]
[gdscript]
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%
[/gdscript]
[csharp]
var bg = new Color(0.0f, 1.0f, 0.0f, 0.5f); // Green with alpha of 50%
var fg = new Color(1.0f, 0.0f, 0.0f, 0.5f); // Red with alpha of 50%
Color blendedColor = bg.Blend(fg); // Brown with alpha of 75%
[/csharp]
[/codeblocks]
Returns a new color with all components clamped between the components of [param min] and [param max], by running [method @GlobalScope.clamp] on each component.
Returns a new color resulting from making this color darker by the specified [param amount] (ratio from 0.0 to 1.0). See also [method lightened].
[codeblocks]
[gdscript]
var green = Color(0.0, 1.0, 0.0)
var darkgreen = green.darkened(0.2) # 20% darker than regular green
[/gdscript]
[csharp]
var green = new Color(0.0f, 1.0f, 0.0f);
Color darkgreen = green.Darkened(0.2f); // 20% darker than regular green
[/csharp]
[/codeblocks]
Constructs a color from an [url=https://en.wikipedia.org/wiki/HSL_and_HSV]HSV profile[/url]. The hue ([param h]), saturation ([param s]), and value ([param v]) are typically between 0.0 and 1.0.
[codeblocks]
[gdscript]
var color = Color.from_hsv(0.58, 0.5, 0.79, 0.8)
[/gdscript]
[csharp]
var color = Color.FromHsv(0.58f, 0.5f, 0.79f, 0.8f);
[/csharp]
[/codeblocks]
Constructs a color from an [url=https://bottosson.github.io/posts/colorpicker/]OK HSL profile[/url]. The hue ([param h]), saturation ([param s]), and lightness ([param l]) are typically between 0.0 and 1.0.
[codeblocks]
[gdscript]
var color = Color.from_ok_hsl(0.58, 0.5, 0.79, 0.8)
[/gdscript]
[csharp]
var color = Color.FromOkHsl(0.58f, 0.5f, 0.79f, 0.8f);
[/csharp]
[/codeblocks]
Encodes a [Color] from a RGBE9995 format integer. See [constant 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 [param 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.
[b]Note:[/b] [method 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 [method srgb_to_linear] to convert it to the linear color space first.
Returns the [Color] associated with the provided [param hex] integer in 32-bit ARGB format (8 bits per channel, alpha channel first).
In GDScript and C#, the [int] is best visualized with hexadecimal notation ([code]"0x"[/code] prefix).
[codeblocks]
[gdscript]
var red = Color.hex(0xffff0000)
var dark_cyan = Color.hex(0xff008b8b)
var my_color = Color.hex(0xa4bbefd2)
[/gdscript]
[csharp]
var red = new Color(0xffff0000);
var dark_cyan = new Color(0xff008b8b);
var my_color = new Color(0xa4bbefd2);
[/csharp]
[/codeblocks]
Returns the [Color] associated with the provided [param hex] integer in 64-bit ARGB format (16 bits per channel, alpha channel first).
In GDScript and C#, the [int] is best visualized with hexadecimal notation ([code]"0x"[/code] prefix).
Returns a new color from [param rgba], an HTML hexadecimal color string. [param rgba] is not case-sensitive, and may be prefixed by a hash sign ([code]#[/code]).
[param rgba] must be a valid three-digit or six-digit hexadecimal color string, and may contain an alpha channel value. If [param rgba] does not contain an alpha channel value, an alpha channel value of 1.0 is applied. If [param rgba] is invalid, returns an empty color.
[b]Note:[/b] In C#, this method is not implemented. The same functionality is provided by the Color constructor.
[codeblocks]
[gdscript]
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)
[/gdscript]
[csharp]
var blue = Color.FromHtml("#0000ff"); // blue is Color(0.0, 0.0, 1.0, 1.0)
var green = Color.FromHtml("#0F0"); // green is Color(0.0, 1.0, 0.0, 1.0)
var col = Color.FromHtml("663399cc"); // col is Color(0.4, 0.2, 0.6, 0.8)
[/csharp]
[/codeblocks]
Returns [code]true[/code] if [param 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 ([code]#[/code]). This method is identical to [method String.is_valid_html_color].
[codeblocks]
[gdscript]
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 false
[/gdscript]
[csharp]
Color.IsHtmlValid("#55AAFF"); // Returns true
Color.IsHtmlValid("#55AAFF20"); // Returns true
Color.IsHtmlValid("55AAFF"); // Returns true
Color.IsHtmlValid("#F2C"); // Returns true
Color.IsHtmlValid("#AABBC"); // Returns false
Color.IsHtmlValid("#55aaFF5"); // Returns false
[/csharp]
[/codeblocks]
Returns the color with its [member r], [member g], and [member b] components inverted ([code](1 - r, 1 - g, 1 - b, a)[/code]).
[codeblocks]
[gdscript]
var black = Color.WHITE.inverted()
var color = Color(0.3, 0.4, 0.9)
var inverted_color = color.inverted() # Equivalent to `Color(0.7, 0.6, 0.1)`
[/gdscript]
[csharp]
var black = Colors.White.Inverted();
var color = new Color(0.3f, 0.4f, 0.9f);
Color invertedColor = color.Inverted(); // Equivalent to `new Color(0.7f, 0.6f, 0.1f)`
[/csharp]
[/codeblocks]
Returns [code]true[/code] if this color and [param to] are approximately equal, by running [method @GlobalScope.is_equal_approx] on each component.
Returns the linear interpolation between this color's components and [param to]'s components. The interpolation factor [param weight] should be between 0.0 and 1.0 (inclusive). See also [method @GlobalScope.lerp].
[codeblocks]
[gdscript]
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)
[/gdscript]
[csharp]
var red = new Color(1.0f, 0.0f, 0.0f);
var aqua = new Color(0.0f, 1.0f, 0.8f);
red.Lerp(aqua, 0.2f); // Returns Color(0.8f, 0.2f, 0.16f)
red.Lerp(aqua, 0.5f); // Returns Color(0.5f, 0.5f, 0.4f)
red.Lerp(aqua, 1.0f); // Returns Color(0.0f, 1.0f, 0.8f)
[/csharp]
[/codeblocks]
Returns a new color resulting from making this color lighter by the specified [param amount], which should be a ratio from 0.0 to 1.0. See also [method darkened].
[codeblocks]
[gdscript]
var green = Color(0.0, 1.0, 0.0)
var light_green = green.lightened(0.2) # 20% lighter than regular green
[/gdscript]
[csharp]
var green = new Color(0.0f, 1.0f, 0.0f);
Color lightGreen = green.Lightened(0.2f); // 20% lighter than regular green
[/csharp]
[/codeblocks]
Returns the color converted to the [url=https://en.wikipedia.org/wiki/SRGB]sRGB[/url] color space. This method assumes the original color is in the linear color space. See also [method 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 [method 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.
[codeblocks]
[gdscript]
var color = Color(1, 0.5, 0.2)
print(color.to_abgr32()) # Prints 4281565439
[/gdscript]
[csharp]
var color = new Color(1.0f, 0.5f, 0.2f);
GD.Print(color.ToAbgr32()); // Prints 4281565439
[/csharp]
[/codeblocks]
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.
[codeblocks]
[gdscript]
var color = Color(1, 0.5, 0.2)
print(color.to_abgr64()) # Prints -225178692812801
[/gdscript]
[csharp]
var color = new Color(1.0f, 0.5f, 0.2f);
GD.Print(color.ToAbgr64()); // Prints -225178692812801
[/csharp]
[/codeblocks]
Returns the color converted to a 32-bit integer in ARGB format (each component is 8 bits). ARGB is more compatible with DirectX.
[codeblocks]
[gdscript]
var color = Color(1, 0.5, 0.2)
print(color.to_argb32()) # Prints 4294934323
[/gdscript]
[csharp]
var color = new Color(1.0f, 0.5f, 0.2f);
GD.Print(color.ToArgb32()); // Prints 4294934323
[/csharp]
[/codeblocks]
Returns the color converted to a 64-bit integer in ARGB format (each component is 16 bits). ARGB is more compatible with DirectX.
[codeblocks]
[gdscript]
var color = Color(1, 0.5, 0.2)
print(color.to_argb64()) # Prints -2147470541
[/gdscript]
[csharp]
var color = new Color(1.0f, 0.5f, 0.2f);
GD.Print(color.ToArgb64()); // Prints -2147470541
[/csharp]
[/codeblocks]
Returns the color converted to an HTML hexadecimal color [String] in RGBA format, without the hash ([code]#[/code]) prefix.
Setting [param with_alpha] to [code]false[/code], excludes alpha from the hexadecimal string, using RGB format instead of RGBA format.
[codeblocks]
[gdscript]
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"
[/gdscript]
[csharp]
var white = new Color(1, 1, 1, 0.5f);
string withAlpha = white.ToHtml(); // Returns "ffffff7f"
string withoutAlpha = white.ToHtml(false); // Returns "ffffff"
[/csharp]
[/codeblocks]
Returns the color converted to a 32-bit integer in RGBA format (each component is 8 bits). RGBA is Godot's default format.
[codeblocks]
[gdscript]
var color = Color(1, 0.5, 0.2)
print(color.to_rgba32()) # Prints 4286526463
[/gdscript]
[csharp]
var color = new Color(1, 0.5f, 0.2f);
GD.Print(color.ToRgba32()); // Prints 4286526463
[/csharp]
[/codeblocks]
Returns the color converted to a 64-bit integer in RGBA format (each component is 16 bits). RGBA is Godot's default format.
[codeblocks]
[gdscript]
var color = Color(1, 0.5, 0.2)
print(color.to_rgba64()) # Prints -140736629309441
[/gdscript]
[csharp]
var color = new Color(1, 0.5f, 0.2f);
GD.Print(color.ToRgba64()); // Prints -140736629309441
[/csharp]
[/codeblocks]
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 [member 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 [member 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 [member 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 [member 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.
Alice blue color.
Antique white color.
Aqua color.
Aquamarine color.
Azure color.
Beige color.
Bisque color.
Black color. In GDScript, this is the default value of any color.
Blanched almond color.
Blue color.
Blue violet color.
Brown color.
Burlywood color.
Cadet blue color.
Chartreuse color.
Chocolate color.
Coral color.
Cornflower blue color.
Cornsilk color.
Crimson color.
Cyan color.
Dark blue color.
Dark cyan color.
Dark goldenrod color.
Dark gray color.
Dark green color.
Dark khaki color.
Dark magenta color.
Dark olive green color.
Dark orange color.
Dark orchid color.
Dark red color.
Dark salmon color.
Dark sea green color.
Dark slate blue color.
Dark slate gray color.
Dark turquoise color.
Dark violet color.
Deep pink color.
Deep sky blue color.
Dim gray color.
Dodger blue color.
Firebrick color.
Floral white color.
Forest green color.
Fuchsia color.
Gainsboro color.
Ghost white color.
Gold color.
Goldenrod color.
Gray color.
Green color.
Green yellow color.
Honeydew color.
Hot pink color.
Indian red color.
Indigo color.
Ivory color.
Khaki color.
Lavender color.
Lavender blush color.
Lawn green color.
Lemon chiffon color.
Light blue color.
Light coral color.
Light cyan color.
Light goldenrod color.
Light gray color.
Light green color.
Light pink color.
Light salmon color.
Light sea green color.
Light sky blue color.
Light slate gray color.
Light steel blue color.
Light yellow color.
Lime color.
Lime green color.
Linen color.
Magenta color.
Maroon color.
Medium aquamarine color.
Medium blue color.
Medium orchid color.
Medium purple color.
Medium sea green color.
Medium slate blue color.
Medium spring green color.
Medium turquoise color.
Medium violet red color.
Midnight blue color.
Mint cream color.
Misty rose color.
Moccasin color.
Navajo white color.
Navy blue color.
Old lace color.
Olive color.
Olive drab color.
Orange color.
Orange red color.
Orchid color.
Pale goldenrod color.
Pale green color.
Pale turquoise color.
Pale violet red color.
Papaya whip color.
Peach puff color.
Peru color.
Pink color.
Plum color.
Powder blue color.
Purple color.
Rebecca purple color.
Red color.
Rosy brown color.
Royal blue color.
Saddle brown color.
Salmon color.
Sandy brown color.
Sea green color.
Seashell color.
Sienna color.
Silver color.
Sky blue color.
Slate blue color.
Slate gray color.
Snow color.
Spring green color.
Steel blue color.
Tan color.
Teal color.
Thistle color.
Tomato color.
Transparent color (white with zero alpha).
Turquoise color.
Violet color.
Web gray color.
Web green color.
Web maroon color.
Web purple color.
Wheat color.
White color.
White smoke color.
Yellow color.
Yellow green color.
Returns [code]true[/code] if the colors are not exactly equal.
[b]Note:[/b] Due to floating-point precision errors, consider using [method 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 [code]true[/code] if the colors are exactly equal.
[b]Note:[/b] Due to floating-point precision errors, consider using [method is_equal_approx] instead, which is more reliable.
Access color components using their index. [code][0][/code] is equivalent to [member r], [code][1][/code] is equivalent to [member g], [code][2][/code] is equivalent to [member b], and [code][3][/code] is equivalent to [member a].
Returns the same value as if the [code]+[/code] was not there. Unary [code]+[/code] does nothing, but sometimes it can make your code more readable.
Inverts the given color. This is equivalent to [code]Color.WHITE - c[/code] or [code]Color(1 - c.r, 1 - c.g, 1 - c.b, 1 - c.a)[/code]. Unlike with [method inverted], the [member a] component is inverted, too.