Class: Color

Color(ropt, gopt, bopt, aopt)

Class containing colors, either RGB or HSL

Constructor

new Color(ropt, gopt, bopt, aopt)

Create a color by setting the value of its RGB channels.
Parameters:
Name Type Attributes Default Description
r number <optional>
0 The value of the Red channel in range [0, 255]
g number <optional>
0 The value of the Green channel in range [0, 255]
b number <optional>
0 The value of the Blue channel in range [0, 255]
a number <optional>
1 The value of the Alpha channel in range [0, 1]
Source:

Methods

(static) fromCSS(name) → {Color}

Create a color from CSS name. List of name provided by the W3C (https://www.w3.org/wiki/CSS/Properties/color/keywords)
Parameters:
Name Type Description
name string
Source:
Returns:
Type
Color

(static) fromHEX(hex) → {Color}

Create a color from a hexadecimal string
Parameters:
Name Type Description
hex string
Source:
Returns:
Type
Color

(static) fromHSL(h, s, l, a) → {Color}

Create a color from HSL values
Parameters:
Name Type Description
h number Color hue in range [0, 360]
s number Color saturation in range [0, 100]
l number Color lighting in range [0, 100]
a number Color alpha in range [0, 1]
Source:
Returns:
Type
Color

(static) fromMonochrome(ch, aopt) → {Color}

Create a monochrome color from a decimal value
Parameters:
Name Type Attributes Default Description
ch number Red, green and blue value in range [0, 255]
a number <optional>
1 Alpha value in range [0, 1], defaults to 1
Source:
Returns:
Type
Color

(static) fromRGB(r, g, b, a) → {Color}

Create a color from RGB values
Parameters:
Name Type Description
r number Red channel value in range [0, 360]
g number Green channel value in range [0, 360]
b number Blue channel value in range [0, 360]
a number Alpha channel value in range [0, 1]
Source:
Returns:
Type
Color

copy() → {Color}

Return a copy of the color
Source:
Returns:
Type
Color

darken(amount, easing) → {Color}

Darken the color by a certain amount, returning a new color. Optionally, an easing function can be passed to control the mix.
Parameters:
Name Type Default Description
amount number
easing function null
Source:
Returns:
Type
Color

equals(other, compare_alphaopt) → {Boolean}

Checks if two colors are equal
Parameters:
Name Type Attributes Default Description
other Color
compare_alpha Boolean <optional>
true If true, the alpha channel will be compared too
Source:
Returns:
Type
Boolean

lighten(amount, easing) → {Color}

Lighten the color by a certain amount, returning a new color. Optionally, an easing function can be passed to control the mix.
Parameters:
Name Type Default Description
amount number
easing function null
Source:
Returns:
Type
Color

mix(other, amount, easingopt)

Mix two colors, returning a new color. Optionally, an easing function can be passed to control the mix.
Parameters:
Name Type Attributes Default Description
other Color
amount number
easing function <optional>
null
Source:

toString() → {string}

Returns the color as a string
Source:
Returns:
Type
string