new Color(objopt, colorspaceopt)
This class handles multiple color spaces, and offers various static methods for converting colors from one space to another.
The constructor accepts the following color representations:
- a named color, e.g. 'aliceblue' (the colorspace must be RGB)
- an hexadecimal string representation, e.g. '#FF0000' (the colorspace must be RGB)
- an hexadecimal number representation, e.g. 0xFF0000 (the colorspace must be RGB)
- a triplet of numbers, e.g. [-1, 0, 1], [0, 128, 255] (the numbers must be within the range determined by the colorspace)
Note: internally, colors are represented as a [r,g,b] triplet with r,g,b in [0,1].
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
obj |
string | number | Array.<number> | undefined |
<optional> |
'black' | an object representing a color |
colorspace |
module:util.Color#COLOR_SPACE | undefined |
<optional> |
Color.COLOR_SPACE.RGB | the colorspace of that color |
- Source:
- To Do:
-
- implement HSV, DKL, and LMS colorspaces
Members
(readonly) COLOR_SPACE :Symbol
Color spaces.
Type:
- Symbol
- Source:
(readonly) NAMED_COLORS :string
Named colors.
Type:
- string
- Source:
Methods
(static) hex() → {string}
Get the hexadecimal color code equivalent of this Color.
- Source:
Returns:
the hexadecimal color code equivalent
- Type
- string
(static) hexToRgb(hex) → {Array.<number>}
Get the [0,1] RGB triplet equivalent of the hexadecimal color code.
Parameters:
Name | Type | Description |
---|---|---|
hex |
string | the hexadecimal color code |
- Source:
Returns:
the [0,1] RGB triplet equivalent
- Type
- Array.<number>
(static) hexToRgb255(hex) → {Array.<number>}
Get the [0,255] RGB triplet equivalent of the hexadecimal color code.
Parameters:
Name | Type | Description |
---|---|---|
hex |
string | the hexadecimal color code |
- Source:
Returns:
the [0,255] RGB triplet equivalent
- Type
- Array.<number>
(static) int() → {number}
Get the integer code equivalent of this Color.
- Source:
Returns:
the integer code equivalent
- Type
- number
(static) rgb() → {Array.<number>}
Get the [0,1] RGB triplet equivalent of this Color.
- Source:
Returns:
the [0,1] RGB triplet equivalent
- Type
- Array.<number>
(static) rgb255() → {Array.<number>}
Get the [0,255] RGB triplet equivalent of this Color.
- Source:
Returns:
the [0,255] RGB triplet equivalent
- Type
- Array.<number>
(static) rgb255ToHex(rgb255) → {string}
Get the hexadecimal color code equivalent of the [0, 255] RGB triplet.
Parameters:
Name | Type | Description |
---|---|---|
rgb255 |
Array.<number> | the [0, 255] RGB triplet |
- Source:
Returns:
the hexadecimal color code equivalent
- Type
- string
(static) rgb255ToInt(rgb255) → {number}
Get the integer equivalent of the [0, 255] RGB triplet.
Parameters:
Name | Type | Description |
---|---|---|
rgb255 |
Array.<number> | the [0, 255] RGB triplet |
- Source:
Returns:
the integer equivalent
- Type
- number
(static) rgbFull() → {Array.<number>}
Get the [-1,1] RGB triplet equivalent of this Color.
- Source:
Returns:
the [-1,1] RGB triplet equivalent
- Type
- Array.<number>
(static) rgbToHex(rgb) → {string}
Get the hexadecimal color code equivalent of the [0, 1] RGB triplet.
Parameters:
Name | Type | Description |
---|---|---|
rgb |
Array.<number> | the [0, 1] RGB triplet |
- Source:
Returns:
the hexadecimal color code equivalent
- Type
- string
(static) rgbToInt(rgb) → {number}
Get the integer equivalent of the [0, 1] RGB triplet.
Parameters:
Name | Type | Description |
---|---|---|
rgb |
Array.<number> | the [0, 1] RGB triplet |
- Source:
Returns:
the integer equivalent
- Type
- number
(static) toString() → {string}
String representation of the color, i.e. the hexadecimal representation.
- Source:
Returns:
the representation.
- Type
- string