module:Color

module:Color

Color class

Constructor

# new module:Color(…colorDefinition)

Color constructor

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
[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:
Name Type Attributes Description
colorDefinition ColorDefinition <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:
Name Type Description
value Number

Any value between 0 and 1

Returns:

Itself

Type
Color

# 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)

Returns:

Itself

Type
Color

# level(number) → {Color}

Restrict the color space to an amount of possible value

Parameters:
Name Type Description
number Number

Number of allowed value

Returns:

Itself

Type
Color

# 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

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:
Name Type Description
value Number

Any value between 0 and 1

Returns:

Itself

Type
Color

# set(…colorDefinition) → {Color}

Change this values

Parameters:
Name Type Attributes Description
colorDefinition ColorDefinition <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>