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#
| Name | Type |
|---|---|
r | number |
g | number |
b | number |
Defined in#
Properties#
black#
â–ª Static Readonly black: Color
Returns (0, 0, 0).
Defined in#
white#
â–ª Static Readonly white: Color
Returns (1, 1, 1).
Defined in#
Accessors#
b#
• get b(): number
Returns the b-component of the color. Note that this also floors the value.
Returns#
number
Defined in#
• set b(value): void
Modifies the b-component of the color.
Parameters#
| Name | Type |
|---|---|
value | number |
Returns#
void
Defined in#
g#
• get g(): number
Returns the g-component of the color.
Returns#
number
Defined in#
• set g(value): void
Modifies the g-component of the color. Note that this also floors the value.
Parameters#
| Name | Type |
|---|---|
value | number |
Returns#
void
Defined in#
r#
• get r(): number
Returns the r-component of the color.
Returns#
number
Defined in#
• set r(value): void
Modifies the r-component of the color. Note that this also floors the value.
Parameters#
| Name | Type |
|---|---|
value | number |
Returns#
void
Defined in#
rgb#
• get rgb(): [number, number, number]
Returns the rgb-components of the color, bundled as a copied array.
Returns#
[number, number, number]
Defined in#
• set rgb(values): void
Simultaneously updates the rgb-components of the color, by passing an array.
Parameters#
| Name | Type |
|---|---|
values | [number, number, number] |
Returns#
void
Defined in#
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#
| Name | Type | Default value |
|---|---|---|
color | Color | undefined |
weight | number | 0.5 |
Returns#
Defined in#
toHex#
â–¸ toHex(): string
Returns the hexadecimal representation of the color, prefixed by '#'.
Returns#
string
Defined in#
toString#
â–¸ toString(): string
Returns a formatted representation of the color.
Returns#
string
Defined in#
fromHex#
â–¸ Static fromHex(hex): Color
Creates a color from the specified hexadecimal string. This string can optionally be prefixed by '#'.
Parameters#
| Name | Type |
|---|---|
hex | string |
Returns#
Defined in#
fromHsl#
â–¸ Static fromHsl(h, s, l): Color
Creates a color from the specified HSL components.
see https://stackoverflow.com/a/9493060/5507624
Parameters#
| Name | Type |
|---|---|
h | number |
s | number |
l | number |