Colour
Represents an RGBA colour. Note that colour each component is an 8-bit integer (ie. must be between 0
and 255
).
Constants
Name | Value |
---|---|
FORMAT_RGB |
0 |
FORMAT_RGBA |
1 |
FORMAT_HEX |
2 |
FORMAT_ZDOOM |
3 |
Properties
Property | Type | Description |
---|---|---|
Red component | ||
Green component | ||
Blue component | ||
Alpha component (transparency) | ||
Red component as a float (0.0 -1.0 ) |
||
Green component as a float (0.0 -1.0 ) |
||
Blue component as a float (0.0 -1.0 ) |
||
Alpha component as a float (0.0 -1.0 ) |
Constructors
Creates a new colour with all components set to 0
.
Creates a new colour with the given 255
.
Parameters
r (integer ): Red component (0
-255
)g (integer ): Green component (0
-255
)b (integer ): Blue component (0
-255
)
Creates a new colour with the given
Parameters
r (integer ): Red component (0
-255
)g (integer ): Green component (0
-255
)b (integer ): Blue component (0
-255
)a (integer ): Alpha component (0
-255
)
Functions
Overview
Conversion
AsHSL
Gets the colour in HSL colourspace.
Returns
float : The hue value (0.0
-1.0
)float : The saturation value (0.0
-1.0
)float : The lightness value (0.0
-1.0
)
AsLAB
Gets the colour in CIELAB colourspace.
Returns
float : The lightness value (0.0
-1.0
)float : The green-red value (0.0
-1.0
)float : The blue-yellow value (0.0
-1.0
)
AsString
Gets a string representation of the colour in the specified
Parameters
format (integer ): The format of the string representation. SeeFORMAT_
constants above
Returns
string : The colour as a string of the specified format
Example
local colour = Colour.new(100, 150, 200, 150)
App.LogMessage(colour:AsString(Colour.FORMAT_RGB)) -- rgb(100, 150, 200)
App.LogMessage(colour:AsString(Colour.FORMAT_RGBA)) -- rgba(100, 150, 200, 150)
App.LogMessage(colour:AsString(Colour.FORMAT_HEX)) -- #6496C8
App.LogMessage(colour:AsString(Colour.FORMAT_ZDOOM)) -- "64 96 C8"
FromHSL
Sets the colour from the given HSL colourspace values.
Parameters
hue (float ): The hue value to set (0.0
-1.0
)saturation (float ): The saturation value to set (0.0
-1.0
)lightness (float ): The lightness value to set (0.0
-1.0
)