Class: Color

Color(red, green, blue, alpha)

Represents a red, green, blue, alpha, color.

Constructor

new Color(red, green, blue, alpha)

Constructs a color from red, green, blue and alpha values.
Parameters:
Name Type Description
red Number The red component, a number between 0 and 1.
green Number The green component, a number between 0 and 1.
blue Number The blue component, a number between 0 and 1.
alpha Number The alpha component, a number between 0 and 1.
Source:

Members

(static, constant) BLACK :Color

The color black.
Type:
Source:

(static, constant) BLUE :Color

The color blue.
Type:
Source:

(static, constant) CYAN :Color

The color cyan.
Type:
Source:

(static) DARK_GRAY :Color

A dark gray (25% white).
Type:
Source:

(static, constant) GREEN :Color

The color green.
Type:
Source:

(static) LIGHT_GRAY :Color

A light gray (75% white).
Type:
Source:

(static, constant) MAGENTA :Color

The color magenta.
Type:
Source:

(static) MEDIUM_GRAY :Color

A medium gray (50% white).
Type:
Source:

(static, constant) RED :Color

The color red.
Type:
Source:

(static) TRANSPARENT :Color

A transparent color.
Type:
Source:

(static, constant) WHITE :Color

The color white.
Type:
Source:

(static, constant) YELLOW :Color

The color yellow.
Type:
Source:

alpha :Number

This color's alpha component, a number between 0 and 1.
Type:
  • Number
Source:

blue :Number

This color's blue component, a number between 0 and 1.
Type:
  • Number
Source:

green :Number

This color's green component, a number between 0 and 1.
Type:
  • Number
Source:

red :Number

This color's red component, a number between 0 and 1.
Type:
  • Number
Source:

Methods

(static) colorFromByteArray(bytes) → {Color}

Construct a color from an array of color components expressed as byte values.
Parameters:
Name Type Description
bytes Uint8Array A four-element array containing the red, green, blue and alpha color components each in the range [0, 255];
Source:
Returns:
The constructed color.
Type
Color

(static) colorFromBytes(redByte, greenByte, blueByte, alphaByte) → {Color}

Construct a color from specified color components expressed as byte values.
Parameters:
Name Type Description
redByte number The red component in the range [0, 255].
greenByte number The green component in the range [0, 255].
blueByte number The blue component in the range [0, 255].
alphaByte number The alpha component in the range [0, 255].
Source:
Returns:
The constructed color.
Type
Color

clone() → {Color}

Create a copy of this color.
Source:
Returns:
A new instance containing the color components of this color.
Type
Color

copy(color) → {Color}

Copies the components of a specified color to this color.
Parameters:
Name Type Description
color Color The color to copy.
Source:
Throws:
If the specified color is null or undefined.
Type
ArgumentError
Returns:
This color set to the red, green, blue and alpha values of the specified color.
Type
Color

equals(color) → {Boolean}

Indicates whether this color is equal to a specified color after converting the floating-point component values of each color to byte values.
Parameters:
Name Type Description
color Color The color to test,
Source:
Returns:
true if the colors are equal, otherwise false.
Type
Boolean

equalsBytes(bytes) → {Boolean}

Indicates whether this color is equal to another color expressed as an array of bytes.
Parameters:
Name Type Description
bytes Uint8Array The red, green, blue and alpha color components.
Source:
Returns:
true if the colors are equal, otherwise false.
Type
Boolean

nextColor() → {Color}

Computes and sets this color to the next higher RBG color. If the color overflows, this color is set to (1 / 255, 0, 0, *), where * indicates the current alpha value.
Source:
Returns:
This color, set to the next possible color.
Type
Color

premultipliedComponents(array) → {Float32Array}

Returns this color's components premultiplied by this color's alpha component.
Parameters:
Name Type Description
array Float32Array A pre-allocated array in which to return the color components.
Source:
Returns:
This colors premultiplied components as an array, in the order RGBA.
Type
Float32Array

set(red, green, blue, alpha) → {Color}

Assigns the components of this color.
Parameters:
Name Type Description
red Number The red component, a number between 0 and 1.
green Number The green component, a number between 0 and 1.
blue Number The blue component, a number between 0 and 1.
alpha Number The alpha component, a number between 0 and 1.
Source:
Returns:
This color with the specified components assigned.
Type
Color

toByteString() → {String}

Returns a string representation of this color, indicating the byte values corresponding to this color's floating-point component values.
Source:
Returns:
Type
String

toHexString(isUsingAlpha) → {string}

Create a hex color string that CSS can use. Optionally, inhibit capturing alpha, because some uses reject a four-component color specification.
Parameters:
Name Type Description
isUsingAlpha Boolean Enable the use of an alpha component.
Source:
Returns:
A color string suitable for CSS.
Type
string

toRGBAString() → {string}

Create a rgba color string that CSS can use.
Source:
Returns:
A color string suitable for CSS.
Type
string