Skip to content

Color class

Rohit Vighne edited this page Aug 22, 2016 · 1 revision

Represents an RGB color. It can decay into a CSS color string for use with an HTML5 Canvas.

Constructor

let clr = new Color(Number red, Number green, Number blue)

Returns a new Color object with the given red, green, and blue values.

Properties

red

clr.red -> Number

The red component of the color. May be modified directly.

green

clr.green -> Number

The green component of the color. May be modified directly.

blue

clr.blue -> Number

The blue component of the color. May be modified directly.

Methods

trunc

clr.trunc() -> Color

Converts the red, green, and blue components into integers. No rounding is performed, instead the decimal part is simply truncated off. Returns a reference to the modified clr.

toString

String(clr)

Returns the CSS color representation of clr. Each of the color components must be positive 8-bit integers (0 to 255 inclusive).

Static methods

lerp

Color.lerp(Color from, Color to, Number pos) -> Color

Linearly interpolates between from and to by pos and returns the result as a new Color. pos is clamped to the range 0 to 1 inclusive.

Clone this wiki locally