Class Color

RGBA representation of a color. Color instances are returned by Properties.get when you retrieve the value of a color property. Palette functions also return Color instances.

Hierarchy

  • Color

Index

Constructors

Properties

Methods

Constructors

constructor

  • new Color(_r: number, _g: number, _b: number, _a: number): Color
  • Create a color from red (0-255), green (0-255), blue (0-255) and alpha (0-1) channels.

    Parameters

    • _r: number

      The red value of the color (0-255).

    • _g: number

      The green value of the color (0-255).

    • _b: number

      The blue value of the color (0-255).

    • _a: number

      The alpha value of the color (0-1).

    Returns Color

Properties

a

a: number

A double for the alpha value (0-1).

b

b: number

An unsigned byte value (0-255) representing the blue channel value.

g

g: number

An unsigned byte value (0-255) representing the green channel value.

r

r: number

An unsigned byte value (0-255) representing the red channel value.

Methods

toString

  • toString(): string
  • Returns string

    An rgb or rbga string representation of the color.

Static fromObject

  • fromObject(_obj: object): Color
  • Creates a Color instance given an object with r, g, b and an optional a attribute.

    Parameters

    • _obj: object

      An object from which to create a Color instance.

    Returns Color

    A Color instance.

    // Create a color from an rgb object.
    const color1 = Color.fromObject( { r: 1, g: 2, b: 3 } );
    
    // Clone the first color and change the 'g' value to 20.
    const color2 = Color.fromObject( { ...color, g: 20 } );