Last modified: 03 January 2025
This type is a color used within the rendering system.
Do not mistake this type with color
that is used in game! While these types are interchangeable internally, they are NOT in the API.
Creates a new color instance.
Arguments
1. Default color (translucent black).
None.
2. Integer colors.
Name
Type
Description
r
int
Red color (0
to 255
).
g
int
Green color (0
to 255
).
b
int
Blue color (0
to 255
).
a
int
Opacity (0
to 255
). Defaults to 255
.
3. Hex string.
Name
Type
Description
hex
string
Hex string. Formats are: #rrggbbaa
, #rrggbb
, #rgba
and #rgb
.
Returns
Type
Description
color
Color object.
Example
local white = draw.color(255, 255, 255);
Returns a white, opaque color.
Arguments
None.
Returns
Type
Description
color
Color object.
Example
local white = draw.color.white();
Returns a white, transparent color.
Arguments
None.
Returns
Type
Description
color
Color object.
Example
local white_t = draw.color.white_transparent();
Returns a black, opaque color.
Arguments
None.
Returns
Type
Description
color
Color object.
Example
local black = draw.color.black();
Returns a black, transparent color.
Arguments
None.
Returns
Type
Description
color
Color object.
Example
local black_t = draw.color.black_transparent();
Returns a red-to-green color, depending on the provided percent.
Arguments
Name
Type
Description
p
float
Percentile (0
to 1
).
a
float
Opacity. Defaults to 1
.
Returns
Type
Description
color
Color object.
Example
local yellow = draw.color.percent(0.5);
Returns a black-to-white color, depending on the provided percent.
Arguments
Name
Type
Description
b
float
Percentile (0
to 1
).
a
float
Opacity. Defaults to 1
.
Returns
Type
Description
color
Color object.
Example
local gray = draw.color.gray(0.5);
Interpolates two colors.
Arguments
Name
Type
Description
a
color
Starting color.
b
color
Ending color.
t
float
Interpolation percentile.
Returns
Type
Description
color
Color object.
Example
local a = draw.color.white();
local b = draw.color.black();
local i = draw.color.interpolate(a, b, 0.5); -- gray
Returns integer representation of this color (RGBA format)
Arguments
None.
Returns
Type
Description
int
RGBA color.
Example
local num = col:rgba();
Returns integer representation of this color (ARGB format)
Arguments
None.
Returns
Type
Description
int
ARGB color.
Example
local num = col:argb();
Returns integer representation of this color (BGRA format)
Arguments
None.
Returns
Type
Description
int
BGRA color.
Example
local num = col:bgra();
Returns integer representation of this color (ABGR format)
Arguments
None.
Returns
Type
Description
int
ABGR color.
Example
local num = col:abgr();
Returns darker variant of this color.
Arguments
Name
Type
Description
value
float
Modulation amount (0
to 1
).
Returns
Type
Description
color
Darker color.
Example
local darker = col:darken(0.5);
Modulate opacity of the color. This will take existing opacity, and multiply it by whatever value you provide. It is useful if you want to modulate same color in steps, instead of setting the accurate opacity number.
Arguments
1. Float variant.
Name
Type
Description
value
float
Opacity modulation (0
to 1
).
2. Integer variant.
Name
Type
Description
value
int
Opacity modulation (0
to 255
).
Returns
Type
Description
color
Modulated color.
Example
local half_opacity = col:mod_a(0.5);
Override red and return new color.
Arguments
Name
Type
Description
value
float
New value.
Returns
Type
Description
color
New color.
Example
local full_red = col:r(1);
Override green and return new color.
Arguments
Name
Type
Description
value
float
New value.
Returns
Type
Description
color
New color.
Example
local full_green = col:g(1);
Override blue and return new color.
Arguments
Name
Type
Description
value
float
New value.
Returns
Type
Description
color
New color.
Example
local full_blue = col:b(1);
Override opacity and return new color.
Arguments
Name
Type
Description
value
float
New value.
Returns
Type
Description
color
New color.
Example
local full_opacity = col:a(1);
Returns red color value.
Arguments
None.
Returns
Type
Description
int
Color value.
Example
local r = col:get_r();
Returns green color value.
Arguments
None.
Returns
Type
Description
int
Color value.
Example
local g = col:get_g();
Returns blue color value.
Arguments
None.
Returns
Type
Description
int
Color value.
Example
local b = col:get_b();
Returns opacity color value.
Arguments
None.
Returns
Type
Description
int
Color value.
Example
local a = col:get_a();
Return hue value of the color.
Arguments
None.
Returns
Type
Description
int
Hue (0
to 359
).
Example
local hue = col:h();
Returns saturation value of the color.
Arguments
None.
Returns
Type
Description
float
Saturation (0
to 1
).
Example
local saturation = col:s();
Returns brightness value of the color.
Arguments
None.
Returns
Type
Description
float
Brightness (0
to 1
).
Example
local brightness = col:v();
Construct new color from provided HSB values.
Arguments
Name
Type
Description
hue
int
Hue (0
to 359
).
saturation
float
Saturation (0
to 1
).
brightness
float
Brightness (0
to 1
).
alpha
float
Override opacity of the source color. Must be either left out, or provided 0
to 1
value.
Returns
Type
Description
color
New color.
Example
local new_col = col:hsv(250, 0.5, 0.1);