Class: Color

Color

Color is an object representing an RGBA color. It can contain HDR values (> 1).


new Color(rOrHex, g, b, a)

Parameters:
Name Type Description
rOrHex

The red component of the colour or a hexadecimal representation of the entire colour.

g

The green component of the colour or omitted in favor of the hexadecimal representation.

b

The blue component of the colour or omitted in favor of the hexadecimal representation.

a

The alpha component of the colour or omitted in favor of the hexadecimal representation.

Author:
  • derschmale <http://www.derschmale.com>

Members


<static> BLACK

Preset for black with alpha 1


<static> BLUE

Preset for blue


<static> CYAN

Preset for cyan


<static> GREEN

Preset for green


<static> HALF

Preset for 50% rgb and alpha


<static> MAGENTA

Preset for magenta


<static> RED

Preset for red


<static> WHITE

Preset for white


<static> YELLOW

Preset for yellow


<static> ZERO

Preset for black with alpha 0


a :number

The alpha component of the colour.

Type:
  • number

b :number

The blue component of the colour.

Type:
  • number

g :number

The green component of the colour.

Type:
  • number

r :number

The green component of the colour.

Type:
  • number

Methods


<static> lerp(a, b, t [, target])

Linearly interpolates between two Colors.

Parameters:
Name Type Argument Description
a Color

The first color to interpolate from.

b Color

The second color to interpolate to.

t Number

The interpolation factor.

target Color <optional>

An optional target color. If not provided, a new Color object will be created and returned.

Returns:

The interpolated color.

Type
Color

clone()

Returns a copy of this Color.


copyFrom()

Copies the values from another Color object.


gammaToLinear( [target])

Converts the color from gamma space to linear space.

Parameters:
Name Type Argument Description
target <optional>

An optional target Color. If not provided, a new Color object will be created and returned.

See:
Returns:

The Color in linear space.

Type
Color

hex()

Returns a numerical representation of the entire colour. Only works for non-HDR color values.


linearToGamma( [target])

Converts the color from linear space to gamma space.

Parameters:
Name Type Argument Description
target <optional>

An optional target Color. If not provided, a new Color object will be created and returned.

See:
Returns:

The Color in linear space.

Type
Color

luminance()

Returns the luminance value of the color.


scale()

Scales all components (except alpha).


set(rOrHex, g, b, a)

Sets the color values directly.

Parameters:
Name Type Description
rOrHex

The red component of the colour or a hexadecimal representation of the entire colour.

g

The green component of the colour or omitted in favor of the hexadecimal representation.

b

The blue component of the colour or omitted in favor of the hexadecimal representation.

a

The alpha component of the colour or omitted in favor of the hexadecimal representation.