Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Color

A color represented by RGB components. The range for each component is from 0 to 1.

Hierarchy

  • Color

Implements

  • Iterable<number>

Index

Constructors

constructor

  • new Color(r: number, g: number, b: number, a?: number): Color
  • Make a color from individual color components (RGB space). Each component can have values between 0 and 1.

    Parameters

    • r: number

      Red component. Default: 0

    • g: number

      Green component. Default: 0

    • b: number

      Blue component. Default: 0

    • Optional a: number

      Alpha component. Default: 1

    Returns Color

Properties

0

0: number

Index for red component

1

1: number

Index for green component

2

2: number

Index for blue component

3

3: number

Index for alpha value

a

a: number

Alpha value

b

b: number

Blue component

g

g: number

Green component

r

r: number

Red component

Methods

[Symbol.iterator]

  • [Symbol.iterator](): Iterator<number>

clone

multiply

  • multiply(f: number): Color
  • Multiply element-wise (f*r, f*g, f*b, f*a)

    Parameters

    • f: number

    Returns Color

toHex

  • toHex(): string
  • Convert to a hexadecimal string in the form 'RRGGBBAA'

    Returns string

toString

  • toString(): string
  • Convert to a string in the form '(R=,G=,B=,A=)'

    Returns string

toVector

Static interpolateTo

  • interpolateTo(current: Color | [r: number, g: number, b: number, a: number], target: Color | [r: number, g: number, b: number, a: number], deltaTime: number, interpSpeed: number): Color
  • Smoothly interpolate towards a varying target color

    Parameters

    • current: Color | [r: number, g: number, b: number, a: number]

      Current color

    • target: Color | [r: number, g: number, b: number, a: number]

      Target color

    • deltaTime: number

      Time since last tick

    • interpSpeed: number

      Interpolation speed

    Returns Color

Static lerp

  • lerp(a: Color | [r: number, g: number, b: number, a: number], b: Color | [r: number, g: number, b: number, a: number], alpha: number): Color
  • Linearly interpolate between a and b based on alpha

    Parameters

    • a: Color | [r: number, g: number, b: number, a: number]

      First color

    • b: Color | [r: number, g: number, b: number, a: number]

      Second color

    • alpha: number

      Result is 100% of a when alpha=0 and 100% of b when alpha=1

    Returns Color