Skip to content

UWAL / Color

Type Aliases

ColorParam

ts
type ColorParam = Color | GPUColor;

Type Parameters

Type Parameter

Classes

Color

Utility class to convert, adjust and compare color values.

Constructors

Constructor
ts
new Color(
   hexOrRed?, 
   green?, 
   blue?, 
   alpha?): Color;

Create a new color instance from a single hex value or using 3 to 4 channel components in [0 - 255] format.

Parameters
ParameterTypeDefault valueDescription
hexOrRed?number0x000000Hex or red channel value
green?numberundefinedGreen channel value
blue?numberundefinedBlue channel value
alpha?number0xffAlpha value
Returns

Color

Methods

Set()
ts
Set(hex, alpha?): Color;

Override this color value.

Parameters
ParameterTypeDefault valueDescription
hexnumberundefinedHex value
alpha?number0xffAlpha value
Returns

Color

Premultiply()
ts
Premultiply(alpha?, dst?): Color;

Multiply this color with an alpha value.

Parameters
ParameterTypeDescription
alpha?numberAlpha value to multiply, defaults to this color alpha if not provided
dst?ColorDestination color, a new Color instance will be created if not provided
Returns

Color

Random()
ts
Random(alpha?): Color;

Set this color to a random value.

Parameters
ParameterTypeDefault valueDescription
alpha?number1Alpha value to keep. Call with undefined to randomize it
Returns

Color

Equals()
ts
Equals(color): boolean;

Compare this color value with the provided one.

Parameters
ParameterTypeDescription
colornumber | ColorParamColor to compare
Returns

boolean

Accessors

rgb
Get Signature
ts
get rgb(): number[];
Returns

number[]

This color components in [0 - 1] format. Alpha is omitted.

Set Signature
ts
set rgb(values): void;

Set this color components using [0 - 1] format. Alpha defaults to 1 if not provided.

Parameters
ParameterTypeDescription
valuesnumber[]3 to 4 color channels
Returns

void

a
Get Signature
ts
get a(): number;
Returns

number

This color alpha in [0 - 1] format.

Set Signature
ts
set a(value): void;

Set this color alpha in [0 - 1] format.

Parameters
ParameterTypeDescription
valuenumberAlpha value
Returns

void

rgba
Get Signature
ts
get rgba(): number[];
Returns

number[]

This color components in [0 - 1] format.

Set Signature
ts
set rgba(values): void;

Set this color components using [0 - 1] format.

Alias

Color.rgb

Parameters
ParameterTypeDescription
valuesnumber[]3 to 4 color channels
Returns

void

RGB
Get Signature
ts
get RGB(): number[];
Returns

number[]

This color components in [0 - 255] format. Alpha is omitted.

Set Signature
ts
set RGB(values): void;

Set this color components using [0 - 255] format. Alpha defaults to 255 if not provided.

Parameters
ParameterTypeDescription
valuesnumber[]3 to 4 color channels
Returns

void

A
Get Signature
ts
get A(): number;
Returns

number

This color alpha in [0 - 255] format.

Set Signature
ts
set A(value): void;

Set this color alpha in [0 - 255] format.

Parameters
ParameterTypeDescription
valuenumberAlpha value
Returns

void

RGBA
Get Signature
ts
get RGBA(): number[];
Returns

number[]

This color components in [0 - 255] format.

Set Signature
ts
set RGBA(values): void;

Set this color components using [0 - 255] format.

Alias

Color.RGB

Parameters
ParameterTypeDescription
valuesnumber[]3 to 4 color channels
Returns

void

Released under the MIT License.