A representation of a color in hexadecimal format. This class provides methods for transformations and manipulations of colors.

Hierarchy

  • Number
    • Color

Accessors

  • get valid(): boolean
  • Is this a valid color?

    Returns boolean

  • get css(): string
  • A CSS-compatible color string. If this color is not valid, the empty string is returned. An alias for Color#toString.

    Returns string

  • get rgb(): [number, number, number]
  • The color represented as an RGB array.

    Returns [number, number, number]

  • get r(): number
  • The numeric value of the red channel between [0, 1].

    Returns number

  • get g(): number
  • The numeric value of the green channel between [0, 1].

    Returns number

  • get b(): number
  • The numeric value of the blue channel between [0, 1].

    Returns number

  • get maximum(): number
  • The maximum value of all channels.

    Returns number

  • get minimum(): number
  • The minimum value of all channels.

    Returns number

  • get littleEndian(): number
  • Get the value of this color in little endian format.

    Returns number

  • get hsv(): [number, number, number]
  • The color represented as an HSV array. Conversion formula adapted from http://en.wikipedia.org/wiki/HSV_color_space. Assumes r, g, and b are contained in the set [0, 1] and returns h, s, and v in the set [0, 1].

    Returns [number, number, number]

  • get hsl(): [number, number, number]
  • The color represented as an HSL array. Assumes r, g, and b are contained in the set [0, 1] and returns h, s, and l in the set [0, 1].

    Returns [number, number, number]

Methods

  • Parameters

    • radix: any

    Returns string

  • Serialize the Color.

    Returns string

    The color as a CSS string

  • Returns the color as a CSS string.

    Returns string

    The color as a CSS string

  • Test whether this color equals some other color

    Parameters

    • other: number | Color

      Some other color or hex number

    Returns boolean

    Are the colors equal?

  • Get a CSS-compatible RGBA color string.

    Parameters

    • alpha: number

      The desired alpha in the range [0, 1]

    Returns string

    A CSS-compatible RGBA string

  • Mix this Color with some other Color using a provided interpolation weight.

    Parameters

    • other: Color

      Some other Color to mix with

    • weight: number

      The mixing weight placed on this color where weight is placed on the other color

    Returns Color

    The resulting mixed Color

  • Multiply this Color by another Color or a static scalar.

    Parameters

    • other: number | Color

      Some other Color or a static scalar.

    Returns Color

    The resulting Color.

  • Add this Color by another Color or a static scalar.

    Parameters

    • other: number | Color

      Some other Color or a static scalar.

    Returns Color

    The resulting Color.

  • Subtract this Color by another Color or a static scalar.

    Parameters

    • other: number | Color

      Some other Color or a static scalar.

    Returns Color

    The resulting Color.

  • Max this color by another Color or a static scalar.

    Parameters

    • other: number | Color

      Some other Color or a static scalar.

    Returns Color

    The resulting Color.

  • Min this color by another Color or a static scalar.

    Parameters

    • other: number | Color

      Some other Color or a static scalar.

    Returns Color

    The resulting Color.

  • Set an rgb array with the rgb values contained in this Color class.

    Parameters

    • vec3: number[]

      Receive the result. Must be an array with at least a length of 3.

    Returns void

  • Iterating over a Color is equivalent to iterating over its [r,g,b] color channels.

    Returns Generator<number, any, any>

  • Apply a linear interpolation between two colors, according to the weight.

    Parameters

    • color1: number

      The first color to mix.

    • color2: number

      The second color to mix.

    • weight: number

      Weight of the linear interpolation.

    Returns number

    The resulting mixed color

  • Multiply two colors.

    Parameters

    • color1: number

      The first color to multiply.

    • color2: number

      The second color to multiply.

    Returns number

    The result.

  • Multiply a color by a scalar

    Parameters

    • color: number

      The color to multiply.

    • scalar: number

      A static scalar to multiply with.

    Returns number

    The resulting color as a number.

  • Maximize two colors.

    Parameters

    • color1: number

      The first color.

    • color2: number

      The second color.

    Returns number

    The result.

  • Maximize a color by a static scalar.

    Parameters

    • color: number

      The color to maximize.

    • scalar: number

      Scalar to maximize with (normalized).

    Returns number

    The resulting color as a number.

  • Add two colors.

    Parameters

    • color1: number

      The first color.

    • color2: number

      The second color.

    Returns number

    The resulting color as a number.

  • Add a static scalar to a color.

    Parameters

    • color: number

      The color.

    • scalar: number

      Scalar to add with (normalized).

    Returns number

    The resulting color as a number.

  • Subtract two colors.

    Parameters

    • color1: number

      The first color.

    • color2: number

      The second color.

    Returns number

  • Subtract a color by a static scalar.

    Parameters

    • color: number

      The color.

    • scalar: number

      Scalar to subtract with (normalized).

    Returns number

    The resulting color as a number.

  • Minimize two colors.

    Parameters

    • color1: number

      The first color.

    • color2: number

      The second color.

    Returns number

  • Minimize a color by a static scalar.

    Parameters

    • color: number

      The color.

    • scalar: number

      Scalar to minimize with (normalized).

    Returns number

  • Convert a color to RGB and assign values to a passed array.

    Parameters

    • color: number

      The color to convert to RGB values.

    • vec3: number[]

      Receive the result. Must be an array with at least a length of 3.

    Returns void

  • Create a Color instance from an RGB array.

    Parameters

    Returns Color

    The hex color instance or NaN

  • Create a Color instance from a color string which either includes or does not include a leading #.

    Parameters

    • color: string

      A color string

    Returns Color

    The hex color instance

  • Create a Color instance from an RGB array.

    Parameters

    • rgb: [number, number, number]

      An RGB tuple

    Returns Color

    The hex color instance

  • Create a Color instance from an RGB normalized values.

    Parameters

    • r: number

      The red value

    • g: number

      The green value

    • b: number

      The blue value

    Returns Color

    The hex color instance

  • Create a Color instance from an HSV array. Conversion formula adapted from http://en.wikipedia.org/wiki/HSV_color_space. Assumes h, s, and v are contained in the set [0, 1].

    Parameters

    • hsv: [number, number, number]

      An HSV tuple

    Returns Color

    The hex color instance

  • Create a Color instance from an HSL array. Assumes h, s, and l are contained in the set [0, 1].

    Parameters

    • hsl: [number, number, number]

      An HSL tuple

    Returns Color

    The hex color instance