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:
- over Color
Returns:
- Color:contrasted ()
-
Returns the most contrasting color.
Returns:
- 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: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: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:linear_interpolate (b, t)
-
Returns the linear interpolation with another color.
The interpolation factor
tis between 0 and 1.Parameters:
- b Color
- t number
Returns:
- Color:to_html ([with_alpha=true])
-
Returns the color's HTML hexadecimal color string in ARGB format (ex: ff34f822).
Setting
with_alphatofalseexcludes alpha from the hexadecimal string.Parameters:
- with_alpha (default true)
Returns:
- Color:unpack ()
-
Returns all elements.
Returns:
- number R
- number G
- number B
- 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:
Metamethods
- Color:__add (a, b)
-
Addition operation
Parameters:
Returns:
- Color:__concat (a, b)
-
Concatenates values.
Parameters:
Returns:
- Color:__div (a, b)
-
Division operation
Parameters:
Returns:
- Color:__eq (a, b)
-
Equality operation
If either
aorbare not of type Color, always returnfalse.Parameters:
Returns:
-
bool
- Color:__lt (a, b)
-
Less than operation
Parameters:
Returns:
-
bool
- Color:__mod (a, b)
-
Module operation
Parameters:
Returns:
- Color:__mul (a, b)
-
Multiplication operation
Parameters:
Returns:
- 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 tor, 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 RGBAColor(number r, number g, Vector2 ba): set RGBAColor(number r, Vector2 gb[, number a = 1]): set RGBAColor(number r, Vector3 gba): set RGBAColor(Vector2 rg[, number b = 0[, number a = 1]]): set RGBAColor(Vector2 rg, Vector2 ba): set RGBAColor(Vector3 rgb[, number a = 1]): set RGBAColor(Color other): copy values fromother
Parameters:
- ...
Returns:
- Color:__pow (a, b)
-
Power operation
Parameters:
Returns:
- Color:__sub (a, b)
-
Subtraction operation
Parameters:
Returns:
- Color:__tostring ()
-
Returns a Lua string representation of this color.
Returns:
- Color:__unm ()
-
Unary minus operation:
1 - selfReturns: