Skip to main content

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

NameTypeDefault ValueDescription
rnumberRequiredThe red component of the colour.
gnumberRequiredThe green component of the colour.
bnumberRequiredThe blue component of the colour.
anumber?1The alpha component of the colour.

Returns

NameTypeDescription
colourColourNo 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

NameTypeDefault ValueDescription
rnumberRequiredThe red component of the colour.
gnumberRequiredThe green component of the colour.
bnumberRequiredThe blue component of the colour.

Returns

NameTypeDescription
colourColourNo 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

NameTypeDefault ValueDescription
rnumberRequiredThe red component of the colour.
gnumberRequiredThe green component of the colour.
bnumberRequiredThe blue component of the colour.
anumberRequiredThe alpha component of the colour.

Returns

NameTypeDescription
colourColourNo description

Colour.fromHex

Creates a colour from a hexadecimal string. Supports #RGB, #RGBA, #RRGGBB and #RRGGBBAA formats.

Colour.fromHex(hex: string): Colour

Parameters

NameTypeDefault ValueDescription
hexstringRequiredThe hexadecimal string.

Returns

NameTypeDescription
colourColourThe new colour.

Colour.toHex

Converts a colour to a hexadecimal string.

Colour.toHex(colour: Colour, withAlpha?: boolean): string

Parameters

NameTypeDefault ValueDescription
colourColourRequiredNo description
withAlphaboolean?trueWhether to include the alpha component (default true).

Returns

NameTypeDescription
hexstringColour 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

FieldTypeDescription
1numberThe red component of the colour.
2numberThe green component of the colour.
3numberThe blue component of the colour.
4numberThe alpha component of the colour.