Data Color
scripts/vscripts/alyxlib/data/color.lua
Methods
ToHexString
Converts this Color to a hexadecimal representation.
The hexadecimal format is in the format #RRGGBB.
Returns
- string
The hexadecimal representation of this Color.
ToVector
Get a Vector from this Color in the form of [x=r, y=g, z=b].
Returns
- Vector
The color vector.
ToDecimalVector
Get a Vector from this Color in the form of [x=r, y=g, z=b] but with ranges [0-1].
Returns
- Vector
The color vector.
SetRGB
Sets the color based on the provided RGB (Red, Green, Blue) components and an optional alpha component. If any of the provided values have fractional parts, they will all be normalized to the range [0, 255]. If any of the provided values are nil or omitted, the corresponding component of the color will remain unchanged.
Parameters
r(optional)
number
The red component of the color.g(optional)
number
The green component of the color.b(optional)
number
The blue component of the color.a(optional)
number
The alpha component of the color.
GetHSL
Get the HSL color values from this Color.
Returns
-
number
h
Hue color value in range [0-360] -
number
s
Saturation color value in range [0-100] -
number
l
Lightness color value in range [0-100]
SetHSL
Sets the color based on the provided HSL (Hue, Saturation, Lightness) components. The method accepts values for hue, saturation, and lightness in their respective ranges and updates the color accordingly.
If any of the provided values have fractional parts, they will be normalized to their appropriate ranges (0 to 360 for hue, 0 to 100 for saturation and lightness). If any of the provided values are nil or omitted, the corresponding component of the color will remain unchanged.
Parameters
h(optional)
number
The hue value of the color (0 to 360), representing the color's position on the color wheel.s(optional)
number
The saturation value of the color (0 to 100), determining the intensity of the color.l(optional)
number
The lightness value of the color (0 to 100), affecting the brightness of the color.
Functions
Color
Create a new Color instance using range [0-1] or [0-255].
Parameters
r(optional)
number
Red color value.g(optional)
number
Green color value.b(optional)
number
Blue color value.a(optional)
number
Alpha value.
Returns
- Color
IsColor
Get if a value is a Color.
Parameters
value
any
Returns
- boolean
Types
Color
Represents a color object with RGB and HSL components.
| Field | Type | Description |
|---|---|---|
| r | integer |
Red component. |
| g | integer |
Green component. |
| b | integer |
Blue component. |
| a | integer |
Alpha component. |
| hue | integer |
Hue component. |
| saturation | integer |
Saturation component. |
| lightness | integer |
Lightness component. |