dot big bang

Developer API
Menu

Class Color

All
  • Public
  • Public/Protected
  • All

Hierarchy

  • Color

Index

Constructors

constructor

  • new Color(r?: string | number, g?: number, b?: number): Color
  • Creates a color from the provided r, g, b values.

    Parameters

    • Optional r: string | number

      (optional) The red component of the color, if arguments g and b are also defined. If they are not defined, r can be an hexadecimal triplet (recommended), another Color instance or a CSS-style string, for example: 'rgb(250, 0,0)', 'rgb(100%,0%,0%)', 'hsl(0, 100%, 50%)', '#ff0000', '#f00', 'red' (or any X11 color name, all 140 color names are supported).

    • Optional g: number

      (optional) If it is defined, the green component of the color.

    • Optional b: number

      (optional) If it is defined, the blue component of the color.

    Returns Color

Properties

b

b: number

Blue channel value between 0 and 1. Default is 1.

g

g: number

Green channel value between 0 and 1. Default is 1.

r

r: number

Red channel value between 0 and 1. Default is 1.

Methods

add

  • Adds the RGB values of color to the RGB values of this color.

    Parameters

    • color: Color

      Color to add to this color.

    Returns Color

addColors

  • Sets this color's RGB values to the sum of the RGB values of color1 and color2.

    Parameters

    • color1: Color

      First color to add.

    • color2: Color

      Second color to add.

    Returns Color

addScalar

  • addScalar(s: number): Color
  • Adds s to the RGB values of this color.

    Parameters

    • s: number

      The number to add to the RGB values of this color.

    Returns Color

clone

  • Returns a new Color with the same r, g and b values as this one.

    Returns Color

convertGammaToLinear

  • convertGammaToLinear(): Color
  • Converts this color from gamma to linear space.

    Returns Color

convertLinearToGamma

  • convertLinearToGamma(): Color
  • Converts this color from linear space to gamma space.

    Returns Color

copy

  • Copies the r, g and b parameters from color into this color.

    Parameters

    • color: Color

      Color to copy.

    Returns Color

copyGammaToLinear

  • copyGammaToLinear(color: Color, gammaFactor: number): Color
  • Copies the given color into this color, and then converts this color from gamma space to linear space.

    Parameters

    • color: Color

      Color to copy.

    • gammaFactor: number

    Returns Color

copyLinearToGamma

  • copyLinearToGamma(color: Color, gammaFactor: number): Color
  • Copies the given color into this color, and then converts this color from linear space to gamma space.

    Parameters

    • color: Color

      Color to copy.

    • gammaFactor: number

    Returns Color

equals

  • equals(color: Color): boolean
  • Compares the RGB values of color with those of this object. Returns true if they are the same, false otherwise.

    Parameters

    • color: Color

      The Color to compare this one against.

    Returns boolean

fromArray

  • fromArray(array: number[], offset?: number): Color
  • Sets this color's components based on an array formatted like [r, g, b]

    Parameters

    • array: number[]

      Array of floats in the form [r, g, b].

    • Optional offset: number

      An optional offset into the array.

    Returns Color

getHSL

  • Convert this Color's r, g and b values to HSL format and returns an object of the form: {h: 0, s: 0, l: 0}

    Parameters

    • Optional target: HSLColor

      The object into which the result will be copied. h, s and l keys are added to the object if not already present.

    Returns HSLColor

getHex

  • getHex(): number
  • Returns the hexadecimal value of this color.

    Returns number

getHexString

  • getHexString(): number
  • Returns the hexadecimal value of this color as a string, without the '#' prefix (for example, 'FFFFFF').

    Returns number

getStyle

  • getStyle(): string
  • Returns the value of this color as a CSS-style string. Example: rgb(255,0,0)

    Returns string

lerp

  • Linearly interpolates this color's RGB values toward the RGB values of color. The alpha argument can be thought of as the ratio between the two colors, where 0.0 is this color and 1.0 is the first argument.

    Parameters

    • color: Color

      Color to converge on.

    • alpha: number

      A number between 0 and 1.

    Returns Color

multiply

  • Multiplies this color's RGB values by the given color's RGB values.

    Parameters

    Returns Color

multiplyScalar

  • multiplyScalar(s: number): Color
  • Multiplies this color's RGB values by s.

    Parameters

    • s: number

      The number to multiply this color's RGB values by.

    Returns Color

offsetHSL

  • offsetHSL(h: number, s: number, l: number): Color
  • Adds the given h, s, and l to this color's values. Internally, this converts this color's RGB values to HSL, adds h, s, and l, and then converts the color back to RGB.

    Parameters

    • h: number
    • s: number
    • l: number

    Returns Color

set

  • See the Constructor above for full details of what value can be. Delegates to .copy, .setStyle, or .setHex depending on input type.

    Parameters

    • value: string | number | Color

      either an instance of Color an hexadecimal integer value, or a css style string

    Returns Color

setHSL

  • setHSL(h: number, s: number, l: number): Color
  • Sets color from HSL values.

    Parameters

    • h: number

      hue value between 0.0 and 1.0

    • s: number

      saturation value between 0.0 and 1.0

    • l: number

      lightness value between 0.0 and 1.0

    Returns Color

setHex

  • setHex(hex: number): Color
  • Sets this color from an hexadecimal value.

    Parameters

    • hex: number

      Color in hexadecimal.

    Returns Color

setRGB

  • setRGB(r: number, g: number, b: number): Color
  • Sets this color from RGB values.

    Parameters

    • r: number

      Red channel value between 0 and 1.

    • g: number

      Green channel value between 0 and 1.

    • b: number

      Blue channel value between 0 and 1.

    Returns Color

setScalar

  • setScalar(scalar: number): Color
  • Sets all three color r, g, b components of this color to the value scalar.

    Parameters

    • scalar: number

      a value between 0.0 and 1.0.

    Returns Color

setStyle

  • setStyle(style: string): Color
  • Sets this color from a CSS-style string. For example, "rgb(250, 0,0)", "rgb(100%, 0%, 0%)", "hsl(0, 100%, 50%)", "#ff0000", "#f00", or "red" (or any X11 color name, all 140 color names are supported). Transluent colors such as "rgba(255, 0, 0, 0.5)" and "hsla(0, 100%, 50%, 0.5)" are also accepted, but the alpha-channel value will be discarded.

    Parameters

    • style: string

      color as a CSS-style string.

    Returns Color

toArray

  • toArray(array?: number[], offset?: number): number[]
  • Returns an array of the form [r, g, b].

    Parameters

    • Optional array: number[]

      An optional array to store the color to.

    • Optional offset: number

      An optional offset into the array.

    Returns number[]