Colour
API for creating and manipulating colours.
Functions
Colour.create
Creates a new colour.
Colour.create(r: number, g: number, b: number, a?: number): Colour
Parameters
| Name | Type | Default Value | Description |
|---|---|---|---|
| r | number | Required | The red component of the colour. |
| g | number | Required | The green component of the colour. |
| b | number | Required | The blue component of the colour. |
| a | number? | 1 | The alpha component of the colour. |
Returns
| Name | Type | Description |
|---|---|---|
| colour | Colour | No description |
Colour.fromRGB8
Creates a colour from RGB components in the range 0-255. Alpha is set to 1.
Colour.fromRGB8(r: number, g: number, b: number): Colour
Parameters
| Name | Type | Default Value | Description |
|---|---|---|---|
| r | number | Required | The red component of the colour. |
| g | number | Required | The green component of the colour. |
| b | number | Required | The blue component of the colour. |
Returns
| Name | Type | Description |
|---|---|---|
| colour | Colour | No description |
Colour.fromRGBA8
Creates a colour from RGBA components in the range 0-255.
Colour.fromRGBA8(r: number, g: number, b: number, a: number): Colour
Parameters
| Name | Type | Default Value | Description |
|---|---|---|---|
| r | number | Required | The red component of the colour. |
| g | number | Required | The green component of the colour. |
| b | number | Required | The blue component of the colour. |
| a | number | Required | The alpha component of the colour. |
Returns
| Name | Type | Description |
|---|---|---|
| colour | Colour | No description |
Colour.fromHex
Creates a colour from a hexadecimal string. Supports #RGB, #RGBA, #RRGGBB and #RRGGBBAA formats.
Colour.fromHex(hex: string): Colour
Parameters
| Name | Type | Default Value | Description |
|---|---|---|---|
| hex | string | Required | The hexadecimal string. |
Returns
| Name | Type | Description |
|---|---|---|
| colour | Colour | The new colour. |
Colour.toHex
Converts a colour to a hexadecimal string.
Colour.toHex(colour: Colour, withAlpha?: boolean): string
Parameters
| Name | Type | Default Value | Description |
|---|---|---|---|
| colour | Colour | Required | No description |
| withAlpha | boolean? | true | Whether to include the alpha component (default true). |
Returns
| Name | Type | Description |
|---|---|---|
| hex | string | Colour encoded as an #RRGGBBAA hex string (or #RRGGBB if withAlpha is false). |
Types
Colour
RGBA colour stored as an array of four numbers in the 0-1 range (or wider for HDR).
type Colour = { [1]: number, [2]: number, [3]: number, [4]: number }
Properties
| Field | Type | Description |
|---|---|---|
| 1 | number | The red component of the colour. |
| 2 | number | The green component of the colour. |
| 3 | number | The blue component of the colour. |
| 4 | number | The alpha component of the colour. |