Dev - Data Types - Color
A complex data type representing an RGBA color value. It can be stated in multiple different ways.
Color Parameters
When methods have color parameters you can define the color in various different ways:
-
Table
with the following structure:
{r, g, b, a}The components are defined this way:
- red: a float value from 0 - 1 (default: 1.0)
- green: a float value from 0 - 1 (default: 1.0)
- blue: a float value from 0 - 1 (default: 1.0)
- alpha: a float value from 0 - 1 (default: 1.0)
To reduce writing effort there are some shortcut notations:
- {br} translates to { r=br, g=br, b=br, a=1.0 } - opaque grayscale
- {br, a} translates to { r=br, g=br, b=br, a=a } - transparent grayscale
- {r, g, b} translates to { r=r, g=g, b=b, a=1.0 } - opaque color
Examples
{1.0, 0, 0}, {0, 0.4, 0}, {0, 0, 1.0}, {0.45, 0.45, 0}, {1.0, 0.5, 0}, {0.5}, {0}, {1.0,0,0,0.5}, {0,0.3} -
String (HTML/CSS Style)
starting with #, containing a color Hex code. Each color component is defined by a value from 00 (0) to FF (255). Possible formats are:
- "#RGB", E.g.: "#F00" for red (internally expands to #FF0000)
- "#RGBA", E.g.: "#0F08" for a semi-transparent green (internally expands to #00FF0088)
- "#RRGGBB", E.g.: "#0000FF" for blue
- "#RRGGBBAA", E.g.: "FFFF0088" for a semi-transparent yellow
-
String (Color Keyword - CSS3/SVG)
containing CSS3 extended color keywords. E.g.: "lime" or "mediumvioletred". See http://www.w3.org/TR/css3-color/#svg-color/ for a complete list.
-
Bool
will become black (false) or white (true).
-
Number/Int
with an RGBA value encoded as 32-bit integer. The easiest way to do this is using Lua's hexadecimal notation: 0xRRGGBBAA. Note that you always have to specify all color components including alpha in this notation (unlike the Hex string notation).
Color Return Values
When a method returns a color, it will be a tuple of 4 numbers with the following structure:
The components are defined this way:
- red: a float value from 0 - 1 (default: 1)
- green: a float value from 0 - 1 (default: 1)
- blue: a float value from 0 - 1 (default: 1)
- alpha: a float value from 0 - 1 (default: 1)