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.
#
ParametersName | 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.
#
Returnsnumber
#
Defined in• set
b(value
): void
Modifies the b-component of the color.
#
ParametersName | Type |
---|---|
value | number |
#
Returnsvoid
#
Defined in#
g• get
g(): number
Returns the g-component of the color.
#
Returnsnumber
#
Defined in• set
g(value
): void
Modifies the g-component of the color. Note that this also floors the value.
#
ParametersName | Type |
---|---|
value | number |
#
Returnsvoid
#
Defined in#
r• get
r(): number
Returns the r-component of the color.
#
Returnsnumber
#
Defined in• set
r(value
): void
Modifies the r-component of the color. Note that this also floors the value.
#
ParametersName | Type |
---|---|
value | number |
#
Returnsvoid
#
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.
#
ParametersName | Type |
---|---|
values | [number , number , number ] |
#
Returnsvoid
#
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.
#
ParametersName | 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 '#'.
#
Returnsstring
#
Defined in#
toStringâ–¸ toString(): string
Returns a formatted representation of the color.
#
Returnsstring
#
Defined in#
fromHexâ–¸ Static
fromHex(hex
): Color
Creates a color from the specified hexadecimal string. This string can optionally be prefixed by '#'.
#
ParametersName | 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
#
ParametersName | Type |
---|---|
h | number |
s | number |
l | number |