Module math.color
Color utilities.
this is apart of the LEEF-math module
Functions
new (r, g, b, a) | The public constructor. |
from_hsv (h, s, v) | Convert hue,saturation,value to color object. |
from_hsva (h, s, v, a) | Convert hue,saturation,value to color object. |
invert (c) | Invert a color. |
lighten (c, v) | Lighten a color by a component-wise fixed amount (alpha unchanged) |
lerp (a, b, s) | Interpolate between two colors. |
unpack (c) | Unpack a color into individual components in 0-1. |
as_255 (c) | Unpack a color into individual components in 0-255. |
darken (c, v) | Darken a color by a component-wise fixed amount (alpha unchanged) |
multiply (c, v) | Multiply a color's components by a value (alpha unchanged) |
alpha (c, v) | directly set alpha channel |
opacity (c, v) | Multiply a color's alpha by a value |
hue (col, hue) | Set a color's hue (saturation, value, alpha unchanged) |
saturation (col, percent) | Set a color's saturation (hue, value, alpha unchanged) |
value (col, percent) | Set a color's value (saturation, hue, alpha unchanged) |
gamma_to_linear (r, g, b, a) | convert gamma to linear. |
linear_to_gamma (r, g, b, a) | convert linear to gamma. |
is_color (a) | Check if color is valid |
to_string (a) | Return a formatted string. |
Fields
hsv_to_color_table | Convert hue,saturation,value table to color object. |
color_to_hsv_table | Convert color to hue,saturation,value table |
Functions
- new (r, g, b, a)
-
The public constructor.
Parameters:
- r
(nil | float | table) can be a table
{r,g,b,a}
, nil for{0,0,0,0}
orr
in rgba. - g number Green component 0-1
- b number Blue component 0-1
- a number Alpha component 0-1
Returns:
-
color
out
- r
(nil | float | table) can be a table
- from_hsv (h, s, v)
-
Convert hue,saturation,value to color object.
Parameters:
- h number hue 0-1
- s number saturation 0-1
- v number value 0-1
Returns:
-
color
out
- from_hsva (h, s, v, a)
-
Convert hue,saturation,value to color object.
Parameters:
- h number hue 0-1
- s number saturation 0-1
- v number value 0-1
- a number alpha 0-1
Returns:
-
color
out
- invert (c)
-
Invert a color.
Parameters:
- c color color to invert
Returns:
-
color
- lighten (c, v)
-
Lighten a color by a component-wise fixed amount (alpha unchanged)
Parameters:
- c color to lighten
- v float amount to increase each component by, 0-1 scale
Returns:
-
color
- lerp (a, b, s)
-
Interpolate between two colors.
Parameters:
- a color at start
- b color at end
- s float in 0-1 progress between the two colors
Returns:
-
color
out
- unpack (c)
-
Unpack a color into individual components in 0-1.
Parameters:
- c color to unpack
Returns:
- float r in 0-1
- float g in 0-1
- float b in 0-1
- float a in 0-1
- as_255 (c)
-
Unpack a color into individual components in 0-255.
Parameters:
- c color to unpack
Returns:
- int r in 0-255
- int g in 0-255
- int b in 0-255
- int a in 0-255
- darken (c, v)
-
Darken a color by a component-wise fixed amount (alpha unchanged)
Parameters:
- c color to darken
- v int amount to decrease each component by, 0-1 scale
Returns:
-
color
out
- multiply (c, v)
-
Multiply a color's components by a value (alpha unchanged)
Parameters:
- c color to multiply
- v number to multiply each component by
Returns:
-
color
out
- alpha (c, v)
-
directly set alpha channel
Parameters:
- c color to alter
- v float new alpha 0-1
Returns:
-
color
out
- opacity (c, v)
-
Multiply a color's alpha by a value
Parameters:
- c color to multiply
- v float to multiply alpha by
Returns:
-
color
out
- hue (col, hue)
-
Set a color's hue (saturation, value, alpha unchanged)
Parameters:
- col color to alter
- hue float to set 0-1
Returns:
-
color
out
- saturation (col, percent)
-
Set a color's saturation (hue, value, alpha unchanged)
Parameters:
- col color to alter
- percent float to set 0-1
Returns:
-
color
out
- value (col, percent)
-
Set a color's value (saturation, hue, alpha unchanged)
Parameters:
- col color to alter
- percent float to set 0-1
Returns:
-
color
out
- gamma_to_linear (r, g, b, a)
-
convert gamma to linear.
https://en.wikipedia.org/wiki/SRGB#FromsRGBtoCIEXYZ
Parameters:
- r float 0-1
- g float 0-1
- b float 0-1
- a float 0-1 (optional)
Returns:
- float r 0-1
- float g 0-1
- float b 0-1
- float a 0-1
- linear_to_gamma (r, g, b, a)
-
convert linear to gamma.
https://en.wikipedia.org/wiki/SRGB#FromCIEXYZtosRGB
Parameters:
- r float 0-1
- g float 0-1
- b float 0-1
- a float 0-1 (optional)
Returns:
- float r 0-1
- float g 0-1
- float b 0-1
- float a 0-1
- is_color (a)
-
Check if color is valid
Parameters:
- a color to test
Returns:
-
boolean
is color
- to_string (a)
-
Return a formatted string.
Parameters:
- a color color to be turned into a string
Returns:
-
string
formatted