Class: Color

Color

The Color class is meant to represent a color and opacity in a consistant manner Colors are stored internally as an RGBA string (CSS/Canvas compatible) for quick access. The color can be provided or generated in the following formats:

String

Type Example
RGB 'rgb(100, 100, 240)'
RGBA 'rgba(100, 100, 240, 0.5)'
HEX '#FF8833' or '#F83'
Name 'black' (Browser supported color names List)
HSL not implemented yet
HSLA not implemented yet

Object

Type Example
RGB {r: 100, g: 100, b: 100}
RGBA {r: 100, g: 100, b: 100, a: 0.5}
HSV {h:240, s: 50, v: 30}

To set the color using any of the above formats, use the setColor method.

new Color(color)

Create a Color using a string or object as described above.

Name Type Description
color String | Object

A color string or object.

Members

hsvObject

Get or set the color using a HSV object.

opacityNumber

Get or set the opacity (alpha) of the color.

rgbObject

Get or set the color using a RGB object.

rgbaObject

Get or set the color using a RGBA object.

rgbaStringString

Return the color as an RGBA string.

rgbStringString

Return the color as an RGB string.

Methods

staticColor.names()

Return a object of color names and their HEX values

copy()

Returns a copy of this color object

equals(color, ignoreAlpha)

Returns true if this color has the same value as the provided color

Name Type Default Description
color Color

This color to compare with

ignoreAlpha Boolean false

Should opacity be considered in the comparison

invert()

Inverts the color

setColor(color)

Set the color using a color string (e.g RGB, RGBA, Hex, HLA) or a color object (e.g. RGB, RGBA, HSV) as described above.

Name Type Description
color String | Object

A color string or object

toString(){String}

Return the class name as a string.

Returns:
Type Description
String
  • 'Color'