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
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
toString() → {string}
Returns the color as a string
Returns:
The hexadecimal representation of the color
- Type
- string
(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, 360] |
g |
number | Green channel value in range [0, 360] |
b |
number | Blue channel value in range [0, 360] |
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