Skip to main content

Color

The Color API is used to represent and work with RGBA colors in Simulo. We don't use 0-255 but rather 0-1 for color components.

A Color global is provided with fields and functions to work with colors, but the term Color is also used to refer to the color type.

Constructor

To create a color, we have several options:

local red = Color:rgb(1, 0, 0); -- or rgba, with an extra 1 at the end
local red = Color:hsv(0, 1, 1); -- or hsva, with an extra 1 at the end
local red = Color:hex(0xff0000);
local red = 0xff0000;

Fields


.r

The red component of the color. Is a number from 0 to 1.


.g

The green component of the color. Is a number from 0 to 1.


.b

The blue component of the color. Is a number from 0 to 1.


.a

The alpha (opacity) component of the color. Is a number from 0 to 1.

Functions

note

Make sure to use :function() and not .function(), or you'll get an error


:get_hex()

Convert the color into a number like 0xff0000


:get_hsv()

Convert the color into three numbers; hue, saturation and value.

Example

local h,s,v = color:get_hsv();

:clone()

Returns a new color with the same components as the original.

Example

local new_color = color:clone();