Constructor
new module:Color(…colorDefinition)
Color constructor
Name | Type | Attributes | Description |
---|---|---|---|
colorDefinition | ColorDefinition | <repeatable> | Many types accepted (other Color instance, color name, hex string, hex number, red/green/blue/alpha value) |
- Source
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
- Source
alpha
Set the transparency channel
- Source
array
Return an array with red, green and blue value
- Source
[0.1, 0.2, 0.3]
blue
Get the blue channel value
- Source
blue
Set the blue channel
- Source
green
Get the green channel value
- Source
green
Set the green channel
- Source
hex
Return hexadecimal rgb notation
- Source
"#123456"
name
Return the closest CSS color name
- Source
"aliceblue"
red
Get the red channel value
- Source
red
Set the red channel
- Source
rgb
Return hexadecimal rgb notation
- Source
"#123456"
Methods
(static) from(…colorDefinition) → {Color}
Return an instance from a generic definition
Name | Type | Attributes | Description |
---|---|---|---|
colorDefinition | ColorDefinition | <repeatable> | Any valid color definition (see constructor) |
- Source
- Type:
- Color
clone() → {Color}
Create a new copy of this color
- Source
- Type:
- Color
grey() → {Color}
Change to its greyscale value
- Source
Itself
- Type:
- Color
hue(value) → {Color}
Change hue value (0 = red, 0.5 = blue, 1 = red, 1.5 = blue ...)
Name | Type | Description |
---|---|---|
value | Number | Any value between 0 and 1 |
- Source
Itself
- Type:
- Color
lerp(colorDefinition, ratio) → {Color}
Change the color toward another color
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) |
- Source
Itself
- Type:
- Color
level(number) → {Color}
Restrict the color space to an amount of possible value
Name | Type | Description |
---|---|---|
number | Number | Number of allowed value |
- Source
Itself
- Type:
- Color
lightness(value) → {Color}
Change lightness value (0 = black, 0.5 = pure color, 1 = white)
Name | Type | Description |
---|---|---|
value | Number | Any value between 0 and 1 |
- Source
Itself
- Type:
- Color
reverse() → {Color}
Invert the color value
- Source
Itself
- Type:
- Color
saturation(value) → {Color}
Change saturation value (0 = grey, 1 = pure color)
Name | Type | Description |
---|---|---|
value | Number | Any value between 0 and 1 |
- Source
Itself
- Type:
- Color
set(…colorDefinition) → {Color}
Change this values
Name | Type | Attributes | Description |
---|---|---|---|
colorDefinition | ColorDefinition | <repeatable> | Any supported color definition (see constructor) |
- Source
Itself
- Type:
- Color
toJSON() → {Array.<Number>}
Return a json ready array
- Source
- Type:
- Array.<Number>
toString() → {String}
- Source
- Type:
- String
Type Definitions
ColorDefinition
- Color |
String | Number | Array.<Number>
- Source