Color

class Color()

An object representing an RGB Color. Values are specified in the 0-255 range.

Constructors

Color.constructor()
Color(r: number, g: number, b: number): Color

Creates a new color object. Values are specified in the 0-255 range.

Parameters

r: number

red color component

g: number

green color component

b: number

blue color component

Returns: Color

Properties

Color.b
b: number
Color.g
g: number
Color.r
r: number

Methods

Color.assign()
assign(color: Color): this

Sets this color equal to another color

Parameters

color: Color

the point whose values will be used to set this color

Returns: this

the color object
Color.copy()
copy(): Color

Creates a copy of this color

Returns: Color

Copy of this color
Color.equals()
equals(color: Color): boolean

Compares this color with another color

Parameters

color: Color

the color to compare with

Returns: boolean

True if the values of this color equal the other. False otherwise.
Color.fromFloatArray()
fromFloatArray(arr: number[]): void

Sets this color from an array of normalized floating point values

Parameters

arr: number[]

Returns: void

Color.getFloatArray()
getFloatArray(): [number, number, number]

Gets an array of floating point values representing this color. Values are clamped in the 0.0 - 1.0 range.

Returns: [number, number, number]

array of floating point values for this color.
Color.set()
set(r: number, g: number, b: number): void

Sets the color object. Values are specified in the 0-255 range.

Parameters

r: number

red color component

g: number

green color component

b: number

blue color component

Returns: void

Color.setFromFloat()
setFromFloat(r: number, g: number, b: number): void

Sets the color object from floating point values. Values are specified in the 0.0-1.0 range.

Parameters

r: number

red color component

g: number

green color component

b: number

blue color component

Returns: void

Color.toFloatArray()
toFloatArray(arr: number[]?): number[]

Populates an array with floating point values for this color. Values are clamped in the 0.0 - 1.0 range.

Parameters

arr: number[] = …

array whose first three elements will be populated with the r,g, and b values of this color respectively.

Returns: number[]

Color.toHexString()
toHexString(): string

Converts the color to a hexadecimal string.

Returns: string

Hexadecimal string representation of the color.
Color.toJson()
toJson(): IColor

Creates an object ready for JSON serialization.

Returns: IColor

The prepared object.
static Color.black()

static

black(): Color

Creates a new color object initialized to black.

Returns: Color

new color object
static Color.blue()

static

blue(): Color

Creates a new color object initialized to blue.

Returns: Color

new color object
static Color.createFromFloat()

static

createFromFloat(r: number, g: number, b: number): Color

Creates a color object from floating point values. Values are specified in the 0.0-1.0 range.

Parameters

r: number

red color component

g: number

green color component

b: number

blue color component

Returns: Color

new color object
static Color.createFromFloatArray()

static

createFromFloatArray(values: number[]): Color

Creates a color object from an array of floating point values. Values are specified in the 0.0-1.0 range.

Parameters

values: number[]

Returns: Color

static Color.fromHexString()

static

fromHexString(hexString: string): Color

Creates a color object from a hexadecimal string.

Parameters

hexString: string

Hexadecimal string representation of the color.

Returns: Color

new color object
static Color.fromJson()

static

fromJson(objData: unknown): Color

Creates a new [[Color]] from an object given by [[toJson]].

Parameters

objData: unknown

An object given by [[toJson]].

Returns: Color

The prepared object.
static Color.green()

static

green(): Color

Creates a new color object initialized to green.

Returns: Color

new color object
static Color.red()

static

red(): Color

Creates a new color object initialized to red.

Returns: Color

new color object
static Color.white()

static

white(): Color

Creates a new color object initialized to white.

Returns: Color

new color object
static Color.yellow()

static

yellow(): Color

Creates a new color object initialized to yellow.

Returns: Color

new color object