Color in RGBA format with some support for ARGB format.
    public struct Color : IEquatable<Color>

A color is represented by red, green, and blue (r, g, b) components. Additionally, a represents the alpha component, 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 > 1.

You can also create a color from standardized color names by using [method @GDScript.ColorN].

Inheritance Chain

Interfaces

Static Methods

    public static Color Color8(byte r8, byte g8, byte b8, byte a8)

    public static Color ColorN(string name, float alpha = 1f)

    public static Color FromHsv(float hue, float saturation, float value, float alpha = 1f)

Constructs a color from an HSV profile. h, s, and v are values between 0 and 1.

[codeblock]

var c = Color.from_hsv(0.58, 0.5, 0.79, 0.8) # Equivalent to HSV(210, 50, 79, 0.8) or Color8(100, 151, 201, 0.8)

[/codeblock]

    public static void ToHsv(Color color, out float hue, out float saturation, out float value)

Constructors

    public Color(float r, float g, float b, float a = 1f)

Constructs a color from an RGBA profile using values between 0 and 1.

[codeblock]

var c = Color(0.2, 1.0, 0.7, 0.8) # Equivalent to RGBA(51, 255, 178, 204)

[/codeblock]

    public Color(int rgba)

Constructs a color from a 32-bit integer (each byte represents a component of the RGBA profile).

[codeblock]

var c = Color(274) # Equivalent to RGBA(0, 0, 1, 18)

[/codeblock]

    public Color(long rgba)

    public Color(string rgba)

Constructs a color from an HTML hexadecimal color string in ARGB or RGB format. See also [method @GDScript.ColorN].

[codeblock]

Each of the following creates the same color RGBA(178, 217, 10, 255)

var c1 = Color(“#ffb2d90a”) # ARGB format with ‘#’

var c2 = Color(“ffb2d90a”) # ARGB format

var c3 = Color(“#b2d90a”) # RGB format with ‘#’

var c4 = Color(“b2d90a”) # RGB format

[/codeblock]

    public Color()

Fields

    public Single a

Alpha value (range 0 to 1).

    public Single b

Blue value (range 0 to 1).

    public Single g

Green value (range 0 to 1).

    public Single r

Red value (range 0 to 1).

Properties

    public int a8 { get; }

Alpha value (range 0 to 255).

    public int b8 { get; }

Blue value (range 0 to 255).

    public int g8 { get; }

Green value (range 0 to 255).

    public float h { get; set; }

HSV hue value (range 0 to 1).

    public int r8 { get; }

Red value (range 0 to 255).

    public float s { get; set; }

HSV saturation value (range 0 to 1).

    public float this[] { get; set; }

    public float v { get; set; }

HSV value (range 0 to 1).

Methods

    public Color Blend(Color over)

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.

[codeblock]

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%

[/codeblock]

    public Color Contrasted()

Returns the most contrasting color.

[codeblock]

var c = Color(0.3, 0.4, 0.9)

var contrasted_color = c.contrasted() # Equivalent to RGBA(204, 229, 102, 255)

[/codeblock]

    public Color Darkened(float amount)

Returns a new color resulting from making this color darker by the specified percentage (ratio from 0 to 1).

[codeblock]

var green = Color(0.0, 1.0, 0.0)

var darkgreen = green.darkened(0.2) # 20% darker than regular green

[/codeblock]

    public override bool Equals(object obj)

    public bool Equals(Color other)

    public override int GetHashCode()

    public Color Inverted()

Returns the inverted color (1 - r, 1 - g, 1 - b, 1 - a).

[codeblock]

var c = Color(0.3, 0.4, 0.9)

var inverted_color = c.inverted() # a color of an RGBA(178, 153, 26, 255)

[/codeblock]

    public Color Lightened(float amount)

Returns a new color resulting from making this color lighter by the specified percentage (ratio from 0 to 1).

[codeblock]

var green = Color(0.0, 1.0, 0.0)

var lightgreen = green.lightened(0.2) # 20% lighter than regular green

[/codeblock]

    public Color LinearInterpolate(Color c, float t)

Returns the linear interpolation with another color. The interpolation factor t is between 0 and 1.

[codeblock]

var c1 = Color(1.0, 0.0, 0.0)

var c2 = Color(0.0, 1.0, 0.0)

var li_c = c1.linear_interpolate(c2, 0.5) # a color of an RGBA(128, 128, 0, 255)

[/codeblock]

    public int ToAbgr32()

Returns the color’s 32-bit integer in ABGR format (each byte represents a component of the ABGR profile). ABGR is the reversed version of the default format.

[codeblock]

var c = Color(1, 0.5, 0.2)

print(c.to_abgr32()) # Prints 4281565439

[/codeblock]

    public long ToAbgr64()

    public int ToArgb32()

Returns the color’s 32-bit integer in ARGB format (each byte represents a component of the ARGB profile). ARGB is more compatible with DirectX.

[codeblock]

var c = Color(1, 0.5, 0.2)

print(c.to_argb32()) # Prints 4294934323

[/codeblock]

    public long ToArgb64()

    public string ToHtml(bool include_alpha = true)

Returns the color’s HTML hexadecimal color string in ARGB format (ex: ff34f822).

Setting with_alpha to false excludes alpha from the hexadecimal string.

[codeblock]

var c = Color(1, 1, 1, 0.5)

var s1 = c.to_html() # Results “7fffffff”

var s2 = c.to_html(false) # Results ‘ffffff’

[/codeblock]

    public int ToRgba32()

Returns the color’s 32-bit integer in RGBA format (each byte represents a component of the RGBA profile). RGBA is Godot’s default format.

[codeblock]

var c = Color(1, 0.5, 0.2)

print(c.to_rgba32()) # Prints 4286526463

[/codeblock]

    public long ToRgba64()

    public override string ToString()

    public string ToString(string format)

Operators

    public static bool operator ==(Color left, Color right)

    public static bool operator >(Color left, Color right)

    public static bool operator !=(Color left, Color right)

    public static bool operator <(Color left, Color right)
Tags: