Constructor
new Color(ropt, gopt, bopt, aopt)
Create a color by setting the value of its RGB channels.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
r |
number |
<optional> |
0 | The value of the Red channel in range [0, 255] |
g |
number |
<optional> |
0 | The value of the Green channel in range [0, 255] |
b |
number |
<optional> |
0 | The value of the Blue channel in range [0, 255] |
a |
number |
<optional> |
1 | The value of the Alpha channel in range [0, 1] |
Methods
copy() → {Color}
Return a copy of the color
Returns:
A new Color instance with the same values
- Type
- Color
darken(amount, easing) → {Color}
Darken the color by a certain amount, returning a new color.
Optionally, an easing function can be passed to control the mix.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
amount |
number | The amount to darken in range [0, 1] | |
easing |
easingFunction | null | An optional easing function that accepts a number in range [0, 1] and returns a number in range [0, 1] |
Returns:
The darkened color
- Type
- Color
equals(other, compare_alphaopt) → {boolean}
Checks if two colors are equal
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
other |
Color | The other color to compare with | ||
compare_alpha |
boolean |
<optional> |
true | If true, the alpha channel will be compared too |
Returns:
True if the colors are equal, false otherwise
- Type
- boolean
lighten(amount, easing) → {Color}
Lighten the color by a certain amount, returning a new color.
Optionally, an easing function can be passed to control the mix.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
amount |
number | The amount to lighten in range [0, 1] | |
easing |
easingFunction | null | An optional easing function that accepts a number in range [0, 1] and returns a number in range [0, 1] |
Returns:
The lightened color
- Type
- Color
mix(other, amount, easingopt) → {Color}
Mix two colors, returning a new color.
Optionally, an easing function can be passed to control the mix.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
other |
Color | The other color to mix with | ||
amount |
number | The amount of the other color in range [0, 1] | ||
easing |
easingFunction |
<optional> |
null | An optional easing function that accepts a number in range [0, 1] and returns a number in range [0, 1] |
Returns:
The mixed color
- Type
- Color
toString() → {string}
Returns the color as a string
Returns:
The hexadecimal representation of the color
- Type
- string
(static) fromCMYK(c, m, y, k, a) → {Color}
Create a color from CMYK values
Parameters:
| Name | Type | Description |
|---|---|---|
c |
number | Cyan channel value in range [0, 100] |
m |
number | Magenta channel value in range [0, 100] |
y |
number | Yellow channel value in range [0, 100] |
k |
number | Black channel value in range [0, 100] |
a |
number | Alpha channel value in range [0, 1] |
Returns:
The created Color instance
- Type
- Color
(static) fromCSS(name) → {Color}
Create a color from CSS name. List of name provided by the W3C (https://www.w3.org/wiki/CSS/Properties/color/keywords)
Parameters:
| Name | Type | Description |
|---|---|---|
name |
string | The CSS color name |
Returns:
The created Color instance
- Type
- Color
(static) fromHEX(hex) → {Color}
Create a color from a hexadecimal string
Parameters:
| Name | Type | Description |
|---|---|---|
hex |
string | The hexadecimal string, with or without the leading # |
Returns:
The created Color instance
- Type
- Color
(static) fromHSL(h, s, l, a) → {Color}
Create a color from HSL values
Parameters:
| Name | Type | Description |
|---|---|---|
h |
number | Color hue in range [0, 360] |
s |
number | Color saturation in range [0, 100] |
l |
number | Color lighting in range [0, 100] |
a |
number | Color alpha in range [0, 1] |
Returns:
The created Color instance
- Type
- Color
(static) fromHex(hex) → {Color}
Create a color from a hexadecimal string
Parameters:
| Name | Type | Description |
|---|---|---|
hex |
string | The hexadecimal string, with or without the leading # |
Returns:
The created Color instance
- Type
- Color
(static) fromMonochrome(ch, aopt) → {Color}
Create a monochrome color from a decimal value
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
ch |
number | Red, green and blue value in range [0, 255] | ||
a |
number |
<optional> |
1 | Alpha value in range [0, 1], defaults to 1 |
Returns:
The created Color instance
- Type
- Color
(static) fromRGB(r, g, b, a) → {Color}
Create a color from RGB values
Parameters:
| Name | Type | Description |
|---|---|---|
r |
number | Red channel value in range [0, 255] |
g |
number | Green channel value in range [0, 255] |
b |
number | Blue channel value in range [0, 255] |
a |
number | Alpha channel value in range [0, 1] |
Returns:
The created Color instance
- Type
- Color
(static) fromSanzoWada(name) → {Color}
Create a color from Sanzo Wada's Dictionary of Color Combinations (https://sanzo-wada.dmbk.io/)
Parameters:
| Name | Type | Description |
|---|---|---|
name |
string | The Sanzo Wada color name |
Returns:
The created Color instance
- Type
- Color