Class Color

Color metatype, wrapper for godot_color.

Construct using the idiom Color(...), which calls __new.

The R, G, B and A components may be accessed through elements or individually with r/g/b/a. Vector2 with two adjacent components may be get/set with the pairs rg/gb/ba. Vector3 with three adjacent components may be get/set with the triplets rgb/gba:

typedef union godot_color {
    uint8_t data[16];
    float elements[4];
    struct { float r, g, b, a; };
    struct { Vector2 rg; Vector2 ba; };
    struct { float _; Vector2 gb; float _; };
    struct { Vector3 rgb; float _; };
    struct { float _; Vector3 gba; };
} godot_color;

Methods

Color:blend (over) Returns a new color resulting from blending this color over another.
Color:contrasted () Returns the most contrasting color.
Color:darkened (amount) Returns a new color resulting from making this color darker by the specified percentage (ratio from 0 to 1).
Color:get_h () Returns the HSV hue of this color, on the range 0 to 1.
Color:get_s () Returns the HSV saturation of this color, on the range 0 to 1.
Color:get_v () Returns the HSV value (brightness) of this color, on the range 0 to 1.
Color:gray () Returns the color's grayscale representation.
Color:inverted () Returns the inverted color (1 - r, 1 - g, 1 - b, a).
Color:lightened (amount) Returns a new color resulting from making this color lighter by the specified percentage (ratio from 0 to 1).
Color:linear_interpolate (b, t) Returns the linear interpolation with another color.
Color:to_html ([with_alpha=true]) Returns the color's HTML hexadecimal color string in ARGB format (ex: ff34f822).
Color:unpack () Returns all elements.

Static Functions

Color:from_hsv (h, s, v[, a=1.0]) Constructs a color from an HSV profile.

Metamethods

Color:__add (a, b) Addition operation
Color:__concat (a, b) Concatenates values.
Color:__div (a, b) Division operation
Color:__eq (a, b) Equality operation If either a or b are not of type Color, always return false.
Color:__lt (a, b) Less than operation
Color:__mod (a, b) Module operation
Color:__mul (a, b) Multiplication operation
Color:__new (...) Color constructor, called by the idiom Color(...).
Color:__pow (a, b) Power operation
Color:__sub (a, b) Subtraction operation
Color:__tostring () Returns a Lua string representation of this color.
Color:__unm () Unary minus operation: 1 - self


Methods

Color:blend (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.

Parameters:

Returns:

    Color
Color:contrasted ()
Returns the most contrasting color.

Returns:

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

Parameters:

  • amount number

Returns:

    Color
Color:get_h ()
Returns the HSV hue of this color, on the range 0 to 1.

Returns:

    number
Color:get_s ()
Returns the HSV saturation of this color, on the range 0 to 1.

Returns:

    number
Color:get_v ()
Returns the HSV value (brightness) of this color, on the range 0 to 1.

Returns:

    number
Color:gray ()
Returns the color's grayscale representation. The gray value is calculated as (r + g + b) / 3.

Returns:

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

Returns:

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

Parameters:

  • amount number

Returns:

    Color
Color:linear_interpolate (b, t)
Returns the linear interpolation with another color. The interpolation factor t is between 0 and 1.

Parameters:

Returns:

    Color
Color:to_html ([with_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.

Parameters:

  • with_alpha (default true)

Returns:

    String
Color:unpack ()
Returns all elements.

Returns:

  1. number R
  2. number G
  3. number B
  4. number A

Static Functions

These don't receive self and should be called directly as Array.static_function(...)
Color:from_hsv (h, s, v[, a=1.0])
Constructs a color from an HSV profile. h, s, and v are values between 0 and 1.

Parameters:

  • h number
  • s number
  • v number
  • a number (default 1.0)

Returns:

    Color

Metamethods

Color:__add (a, b)
Addition operation

Parameters:

Returns:

    Color
Color:__concat (a, b)
Concatenates values.

Parameters:

  • a First value, stringified with GD.str
  • b First value, stringified with GD.str

Returns:

    String
Color:__div (a, b)
Division operation

Parameters:

Returns:

    Color
Color:__eq (a, b)
Equality operation If either a or b are not of type Color, always return false.

Parameters:

Returns:

    bool
Color:__lt (a, b)
Less than operation

Parameters:

Returns:

    bool
Color:__mod (a, b)
Module operation

Parameters:

Returns:

    Color
Color:__mul (a, b)
Multiplication operation

Parameters:

Returns:

    Color
Color:__new (...)

Color constructor, called by the idiom Color(...).

  • Color(): RGB are set to 0, A is set to 1 (Color() == Color(0, 0, 0, 1))
  • Color(number r): RGB are set to r, A is set to 1 (Color(0.5) == Color(0.5, 0.5, 0.5, 1))
  • Color(number r, number g[, number b = 0[, number a = 1]]): set RGBA
  • Color(number r, number g, Vector2 ba): set RGBA
  • Color(number r, Vector2 gb[, number a = 1]): set RGBA
  • Color(number r, Vector3 gba): set RGBA
  • Color(Vector2 rg[, number b = 0[, number a = 1]]): set RGBA
  • Color(Vector2 rg, Vector2 ba): set RGBA
  • Color(Vector3 rgb[, number a = 1]): set RGBA
  • Color(Color other): copy values from other

Parameters:

  • ...

Returns:

    Color
Color:__pow (a, b)
Power operation

Parameters:

Returns:

    Color
Color:__sub (a, b)
Subtraction operation

Parameters:

Returns:

    Color
Color:__tostring ()
Returns a Lua string representation of this color.

Returns:

    string
Color:__unm ()
Unary minus operation: 1 - self

Returns:

    Color
generated by LDoc 1.4.6 Last updated 2023-01-04 08:52:34