module:Color

Color class

Constructor

new module:Color(…colorDefinition)

Color constructor

Parameters:
NameTypeAttributesDescription
colorDefinitionColorDefinition<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
[0.1, 0.2, 0.3]

blue

Get the blue channel value

blue

Set the blue channel

green

Get the green channel value

green

Set the green channel

hex

Return hexadecimal rgb notation

Example
"#123456"

name

Return the closest CSS color name

Example
"aliceblue"

red

Get the red channel value

red

Set the red channel

rgb

Return hexadecimal rgb notation

Example
"#123456"

Methods

(static) from(…colorDefinition) → {Color}

Return an instance from a generic definition

Parameters:
NameTypeAttributesDescription
colorDefinitionColorDefinition<repeatable>

Any valid color definition (see constructor)

Returns:
Type: 
Color

clone() → {Color}

Create a new copy of this color

Returns:
Type: 
Color

grey() → {Color}

Change to its greyscale value

Returns:

Itself

Type: 
Color

hue(value) → {Color}

Change hue value (0 = red, 0.5 = blue, 1 = red, 1.5 = blue ...)

Parameters:
NameTypeDescription
valueNumber

Any value between 0 and 1

Returns:

Itself

Type: 
Color

lerp(colorDefinition, ratio) → {Color}

Change the color toward another color

Parameters:
NameTypeDescription
colorDefinitionColorDefinition

Any other color

ratioNumber

Ratio of distance to move (0 = no change, 0.5 = equal mix, 1 = same as target color)

Returns:

Itself

Type: 
Color

level(number) → {Color}

Restrict the color space to an amount of possible value

Parameters:
NameTypeDescription
numberNumber

Number of allowed value

Returns:

Itself

Type: 
Color

lightness(value) → {Color}

Change lightness value (0 = black, 0.5 = pure color, 1 = white)

Parameters:
NameTypeDescription
valueNumber

Any value between 0 and 1

Returns:

Itself

Type: 
Color

reverse() → {Color}

Invert the color value

Returns:

Itself

Type: 
Color

saturation(value) → {Color}

Change saturation value (0 = grey, 1 = pure color)

Parameters:
NameTypeDescription
valueNumber

Any value between 0 and 1

Returns:

Itself

Type: 
Color

set(…colorDefinition) → {Color}

Change this values

Parameters:
NameTypeAttributesDescription
colorDefinitionColorDefinition<repeatable>

Any supported color definition (see constructor)

Returns:

Itself

Type: 
Color

toJSON() → {Array.<Number>}

Return a json ready array

Returns:
Type: 
Array.<Number>

toString() → {String}

Returns:
Type: 
String

Type Definitions

ColorDefinition

Type:
  • Color | String | Number | Array.<Number>