Skip to main content

Class: Color

components.Color

Represents a color consisting of RGB values. The components of it are represented as integers in the range 0 to 255.

example

const a = new Color(12, 59, 219);
const b = Color.fromHex("#ffa68d");
const result = a.mix(b);

Constructors#

constructor#

new Color(r, g, b)

Creates a new color instance from the specified RGB components.

Parameters#

NameType
rnumber
gnumber
bnumber

Defined in#

components/color.ts:72

Properties#

black#

Static Readonly black: Color

Returns (0, 0, 0).

Defined in#

components/color.ts:88


white#

Static Readonly white: Color

Returns (1, 1, 1).

Defined in#

components/color.ts:84

Accessors#

b#

get b(): number

Returns the b-component of the color. Note that this also floors the value.

Returns#

number

Defined in#

components/color.ts:47

set b(value): void

Modifies the b-component of the color.

Parameters#

NameType
valuenumber

Returns#

void

Defined in#

components/color.ts:53


g#

get g(): number

Returns the g-component of the color.

Returns#

number

Defined in#

components/color.ts:32

set g(value): void

Modifies the g-component of the color. Note that this also floors the value.

Parameters#

NameType
valuenumber

Returns#

void

Defined in#

components/color.ts:39


r#

get r(): number

Returns the r-component of the color.

Returns#

number

Defined in#

components/color.ts:18

set r(value): void

Modifies the r-component of the color. Note that this also floors the value.

Parameters#

NameType
valuenumber

Returns#

void

Defined in#

components/color.ts:25


rgb#

get rgb(): [number, number, number]

Returns the rgb-components of the color, bundled as a copied array.

Returns#

[number, number, number]

Defined in#

components/color.ts:60

set rgb(values): void

Simultaneously updates the rgb-components of the color, by passing an array.

Parameters#

NameType
values[number, number, number]

Returns#

void

Defined in#

components/color.ts:66

Methods#

mix#

mix(color, weight?): Color

Mixes the two color together with an optional mixing weight. This weight is 0.5 by default, perfectly averaging the color.

Parameters#

NameTypeDefault value
colorColorundefined
weightnumber0.5

Returns#

Color

Defined in#

components/color.ts:94


toHex#

toHex(): string

Returns the hexadecimal representation of the color, prefixed by '#'.

Returns#

string

Defined in#

components/color.ts:105


toString#

toString(): string

Returns a formatted representation of the color.

Returns#

string

Defined in#

components/color.ts:113


fromHex#

Static fromHex(hex): Color

Creates a color from the specified hexadecimal string. This string can optionally be prefixed by '#'.

Parameters#

NameType
hexstring

Returns#

Color

Defined in#

components/color.ts:121


fromHsl#

Static fromHsl(h, s, l): Color

Creates a color from the specified HSL components.

see https://stackoverflow.com/a/9493060/5507624

Parameters#

NameType
hnumber
snumber
lnumber

Returns#

Color

Defined in#

components/color.ts:137