Theme:

Color

RGB color stored in linear working color space. Inputs in sRGB (hex, CSS strings) are converted automatically.

Constructor

new Color()                  // white (1, 1, 1)
new Color(0xff0000)          // from hex
new Color('red')             // from CSS color name
new Color('rgb(255, 0, 0)')  // from CSS string
new Color(1, 0, 0)           // from RGB floats

Properties

  • r, g, b — Color components (0-1 in linear space)
  • isColor — Type flag (true)

Static

  • Color.NAMES — Dictionary of X11 color names → hex values

Methods

Setting

  • set(r, g?, b?) — From hex, string, Color, or RGB values
  • setScalar(s) — Set all channels to s
  • setHex(hex, colorSpace?) — From hexadecimal
  • setRGB(r, g, b, colorSpace?) — From RGB
  • setHSL(h, s, l, colorSpace?) — From HSL (all 0-1)
  • setStyle(style, colorSpace?) — From CSS string
  • setColorName(name, colorSpace?) — From X11 color name
  • copy(color), fromArray(array, offset?), fromBufferAttribute(attribute, index)
  • setFromVector3(v) — x→r, y→g, z→b

Getting

  • getHex(colorSpace?) — Hex integer
  • getHexString(colorSpace?) — Hex string (e.g. 'ff0000')
  • getHSL(target, colorSpace?){h, s, l} object
  • getRGB(target, colorSpace?) — Copy to target Color
  • getStyle(colorSpace?) — CSS string (e.g. 'rgb(255,0,0)')

Color Space

  • copySRGBToLinear(color), copyLinearToSRGB(color)
  • convertSRGBToLinear(), convertLinearToSRGB()

Arithmetic

  • add(color), addColors(c1, c2), addScalar(s)
  • sub(color), multiply(color), multiplyScalar(s)

Interpolation

  • lerp(color, alpha), lerpColors(c1, c2, alpha) — RGB lerp
  • lerpHSL(color, alpha) — Lerp through hue spectrum
  • offsetHSL(h, s, l) — Shift HSL values

Transforms

  • applyMatrix3(m) — Transform by 3x3 matrix

Other

  • equals(c), clone()
  • toArray(array?, offset?), toJSON() — Returns hex value