Constructor
#
new module:Color(…colorDefinition)
Parameters:
Name |
Type |
Attributes |
Description |
colorDefinition |
ColorDefinition
|
<repeatable>
|
Many types accepted (other Color instance, color name, hex string, hex number, red/green/blue/alpha value) |
Example
new Color("indigo"); // Any valid CSS color name
new Color("#123456"); // Hex string definition
new Color("#123"); // Hex shorthand string definition, #123 <=> #112233
new Color(0x123456); // Hex number definition
new Color(0.1, 0.2, 0.3); // Red, Green, Blue definition
Every definition can have one more optional parameter for alpha (opacity)
new Color("violet", 0.5);
Members
#
alpha
Get the transparency channel value
#
alpha
Set the transparency channel
#
array
Return an array with red, green and blue value
Example
#
blue
Get the blue channel value
#
blue
#
green
Get the green channel value
#
green
#
hex
Return hexadecimal rgb notation
Example
#
name
Return the closest CSS color name
Example
#
red
Get the red channel value
#
red
#
rgb
Return hexadecimal rgb notation
Example
Methods
#
(static) from(…colorDefinition) → {Color}
Return an instance from a generic definition
Parameters:
Name |
Type |
Attributes |
Description |
colorDefinition |
ColorDefinition
|
<repeatable>
|
Any valid color definition (see constructor) |
#
clone() → {Color}
Create a new copy of this color
#
grey() → {Color}
Change to its greyscale value
#
hue(value) → {Color}
Change hue value (0 = red, 0.5 = blue, 1 = red, 1.5 = blue ...)
Parameters:
Name |
Type |
Description |
value |
Number
|
Any value between 0 and 1 |
#
lerp(colorDefinition, ratio) → {Color}
Change the color toward another color
Parameters:
Name |
Type |
Description |
colorDefinition |
ColorDefinition
|
Any other color |
ratio |
Number
|
Ratio of distance to move (0 = no change, 0.5 = equal mix, 1 = same as target color) |
#
level(number) → {Color}
Restrict the color space to an amount of possible value
Parameters:
Name |
Type |
Description |
number |
Number
|
Number of allowed value |
#
lightness(value) → {Color}
Change lightness value (0 = black, 0.5 = pure color, 1 = white)
Parameters:
Name |
Type |
Description |
value |
Number
|
Any value between 0 and 1 |
#
reverse() → {Color}
#
saturation(value) → {Color}
Change saturation value (0 = grey, 1 = pure color)
Parameters:
Name |
Type |
Description |
value |
Number
|
Any value between 0 and 1 |
#
set(…colorDefinition) → {Color}
Parameters:
Name |
Type |
Attributes |
Description |
colorDefinition |
ColorDefinition
|
<repeatable>
|
Any supported color definition (see constructor) |
#
toJSON() → {Array.<Number>}
Return a json ready array
Returns:
-
Type
-
Array.<Number>
#
toString() → {String}
Type Definitions
#
ColorDefinition
Type:
-
Color
|
String
|
Number
|
Array.<Number>