Hide menu
Loading...
Searching...
No Matches
Color

Defines an RGBA color.

Color components are represented as numbers in the [0, 1] range.

Implements

Constructors

Constructor

new Color(hexCode): Color

Creates a color from a hex code.

Supported formats are #RGB, #RGBA, #RRGGBB, and #RRGGBBAA. If parsing fails, the color remains in the state for which isNull returns true.

Parameters

hexCode

string

Hex color code.

Returns

Color

Constructor

new Color(r?, g?, b?, a?): Color

Creates a color from explicit component values.

Each provided component is clamped to the [0, 1] range. Components omitted during initialization, or explicitly passed as undefined, use default values: 0 for r, g, and b, and 1 for a. If all components are omitted, a color with unset components is created.

Parameters

r?

number

Red component.

g?

number

Green component.

b?

number

Blue component.

a?

number

Alpha component.

Returns

Color

Accessors

a

Get Signature

get a(): number

Returns the alpha component of the color.

Returns

number

Set Signature

set a(a): void

Sets the alpha component of the color. The value is clamped to the [0, 1] range.

Parameters

a

number

Alpha component.

Returns

void

Alpha component.

Implementation of

BaseRGBA.a


b

Get Signature

get b(): number

Returns the blue component of the color.

Returns

number

Set Signature

set b(b): void

Sets the blue component of the color. The value is clamped to the [0, 1] range.

Parameters

b

number

Blue component.

Returns

void

Blue component.

Implementation of

BaseRGBA.b


g

Get Signature

get g(): number

Returns the green component of the color.

Returns

number

Set Signature

set g(g): void

Sets the green component of the color. The value is clamped to the [0, 1] range.

Parameters

g

number

Green component.

Returns

void

Green component.

Implementation of

BaseRGBA.g


r

Get Signature

get r(): number

Returns the red component of the color.

Returns

number

Set Signature

set r(r): void

Sets the red component of the color. The value is clamped to the [0, 1] range.

Parameters

r

number

Red component.

Returns

void

Red component.

Implementation of

BaseRGBA.r

Methods

clone()

clone(): Color

Creates a new Color with the same component values as this color.

Returns

Color


copy()

copy(other): this

Copies component values from another color.

Parameters

other

Color

Other color.

Returns

this


fromRGB()

Call Signature

static fromRGB(rgb): Color

Creates a Color from an object implementing BaseRGB. The alpha component is initialized to 1.

Parameters

rgb

BaseRGB

Object implementing BaseRGB.

Returns

Color

Call Signature

static fromRGB(rgb): Color

Creates a Color from a packed RGB integer in 0xRRGGBB format. The alpha component is initialized to 1.

Parameters

rgb

number

Packed RGB value.

Returns

Color


fromRGBA()

Call Signature

static fromRGBA(rgba): Color

Creates a Color from an object implementing BaseRGBA.

Parameters

rgba

BaseRGBA

Object implementing BaseRGBA.

Returns

Color

Call Signature

static fromRGBA(rgba): Color

Creates a Color from a packed RGBA integer in 0xRRGGBBAA format.

Parameters

rgba

number

Packed RGBA value.

Returns

Color


getValue()

getValue(index): number

Returns a color component by index.

Component indices are 0 for red, 1 for green, 2 for blue, and 3 for alpha. Unset components are reported as 0. If index is outside the [0, 3] range, returns -1.

Parameters

index

number

Component index.

Returns

number


isEqual()

isEqual(other, tolerance?): boolean

Returns true if this color is equal to other within the specified tolerance.

Parameters

other

Color

Other color.

tolerance?

number = Color.coincidenceTolerance

Per-component comparison tolerance. Defaults to 1e-4.

Returns

boolean


isNull()

isNull(): boolean

Returns true if at least one component of the color is unset.

Returns

boolean


setA()

setA(a): this

Sets the alpha component of the color. The value is clamped to the [0, 1] range.

Parameters

a

number

Alpha component.

Returns

this


setB()

setB(b): this

Sets the blue component of the color. The value is clamped to the [0, 1] range.

Parameters

b

number

Blue component.

Returns

this


setG()

setG(g): this

Sets the green component of the color. The value is clamped to the [0, 1] range.

Parameters

g

number

Green component.

Returns

this


setR()

setR(r): this

Sets the red component of the color. The value is clamped to the [0, 1] range.

Parameters

r

number

Red component.

Returns

this


setValue()

setValue(index, value): this

Sets a color component by index.

Component indices are 0 for red, 1 for green, 2 for blue, and 3 for alpha. The value is clamped to the [0, 1] range. If index is outside the [0, 3] range, the call has no effect and the current object is returned unchanged.

Parameters

index

number

Component index.

value

number

Component value.

Returns

this


setValues()

setValues(r?, g?, b?, a?): this

Sets the specified color components.

Each provided value is clamped to the [0, 1] range. Parameters that are undefined are not assigned explicitly. If a color with unset components is initialized by setting at least one component, the remaining unset components are initialized to their default values.

Parameters

r?

number

Red component.

g?

number

Green component.

b?

number

Blue component.

a?

number

Alpha component.

Returns

this


toJSON()

toJSON(): BaseRGBA

Returns a JSON-serializable representation of the color.

Returns

BaseRGBA


toRGB()

toRGB(): number

Returns this color as a packed RGB integer in 0xRRGGBB format.

Returns

number


toRGBA()

toRGBA(): number

Returns this color as a packed RGBA integer in 0xRRGGBBAA format.

Returns

number


toString()

toString(): string

Returns a string representation of the color.

Returns

string