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 from a single hex value or using 3 or 4 channel components.

Parameters ​
ParameterTypeDefault valueDescription
hexOrRed?number0x000000RGB hex or red channel in 0 - 255 format.
green?numberundefinedGreen channel in 0 - 255 format.
blue?numberundefinedBlue channel in 0 - 255 format.
alpha?number1Alpha value in 0 - 1 format.
Returns ​

Color

Methods ​

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

Update this color to a new value.

Parameters ​
ParameterTypeDefault valueDescription
hexnumberundefinedHex value.
alpha?number1Alpha value.
Returns ​

Color

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

Multiply this color with an alpha value.

Parameters ​
ParameterTypeDescription
alpha?numberAlpha value to multiply in 0 - 1 format. Defaults to the color's alpha.
dst?ColorDestination color. A new one is created if omitted.
Returns ​

Color

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

Set this color to a random value.

Parameters ​
ParameterTypeDefault valueDescription
alpha?number1Alpha value. 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 - 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 omitted.

Parameters ​
ParameterTypeDescription
valuesnumber[]3 or 4 color channels.
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 or 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

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 omitted.

Parameters ​
ParameterTypeDescription
valuesnumber[]3 or 4 color channels.
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 or 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

Released under the MIT License.