Color

Color that holds red, green, blue, and alpha values.

Constructor

new Color(red, green, blue, alpha)

Create a new color.
Parameters:
NameTypeDefaultDescription
rednumber0Red value (0-255)
greennumber0Green value (0-255)
bluenumber0Blue value (0-255)
alphanumber1(Optional) Alpha value (0-1)

Methods

copy() → {Color}

Get an exact copy of the color.
Returns:
Cloned color
Type: 
Color

darken(percent)

Darken this color by a specified percentage.
Parameters:
NameTypeDescription
percentnumberPercentage to darken by

get(alpha) → {string}

Get the color in the form of a string. Useful for CSS styling and drawing colors on canvas.
Parameters:
NameTypeDefaultDescription
alphabooleantrueWhether to include alpha (true by default)
Returns:
Resulting color string
Type: 
string

getDarkened(percent) → {Color}

Get a darkened version of the color.
Parameters:
NameTypeDescription
percentnumberPercentage to darken by
Returns:
Resulting color
Type: 
Color

getLightened(percent) → {Color}

Get a lightened version of the color.
Parameters:
NameTypeDescription
percentnumberPercentage to lighten by
Returns:
Resulting color
Type: 
Color

invert()

Invert the color.

lerp(other, point) → {Color}

Linear interpolate with another color.
Parameters:
NameTypeDescription
otherColorOther color to interpolate with
pointnumberPoint (alpha) on the gradient
Returns:
Resulting interpolated color
Type: 
Color

lighten(percent)

Lighten this color by a specified percentage.
Parameters:
NameTypeDescription
percentnumberPercentage to lighten by

set(red, green, blue, alpha)

Set (replace) the values of the color.
Parameters:
NameTypeDefaultDescription
rednumberRed value (0-255)
greennumberGreen value (0-255)
bluenumberBlue value (0-255)
alphanumber1(Optional) Alpha value (0-1)