Create a new Color object.
Optional
r: number | number[] = 0The value of the red component (0-1). Defaults to 0. If r is an array of length 3 or 4, the array will be used to populate all components.
Optional
g: number = 0The value of the green component (0-1). Defaults to 0.
Optional
b: number = 0The value of the blue component (0-1). Defaults to 0.
Optional
a: number = 1The value of the alpha component (0-1). Defaults to 1.
The alpha component of the color.
The blue component of the color.
The green component of the color.
The red component of the color.
Static
Readonly
BLACKA constant color set to black [0, 0, 0, 1].
Static
Readonly
BLUEA constant color set to blue [0, 0, 1, 1].
Static
Readonly
CYANA constant color set to cyan [0, 1, 1, 1].
Static
Readonly
GRAYA constant color set to gray [0.5, 0.5, 0.5, 1].
Static
Readonly
GREENA constant color set to green [0, 1, 0, 1].
Static
Readonly
MAGENTAA constant color set to magenta [1, 0, 1, 1].
Static
Readonly
REDA constant color set to red [1, 0, 0, 1].
Static
Readonly
WHITEA constant color set to white [1, 1, 1, 1].
Static
Readonly
YELLOWA constant color set to yellow [1, 1, 0, 1].
Copies the contents of a source color to a destination color.
A color to copy to the specified color.
Self for chaining.
const src = new pc.Color(1, 0, 0, 1);
const dst = new pc.Color();
dst.copy(src);
console.log("The two colors are " + (dst.equals(src) ? "equal" : "different"));
Reports whether two colors are equal.
The color to compare to the specified color.
True if the colors are equal and false otherwise.
const a = new pc.Color(1, 0, 0, 1);
const b = new pc.Color(1, 1, 0, 1);
console.log("The two colors are " + (a.equals(b) ? "equal" : "different"));
Set the values of the color from a string representation '#11223344' or '#112233'.
A string representation in the format '#RRGGBBAA' or '#RRGGBB'. Where RR, GG, BB, AA are red, green, blue and alpha values. This is the same format used in HTML/CSS.
Self for chaining.
Returns the result of a linear interpolation between two specified colors.
The color to interpolate from.
The color to interpolate to.
The value controlling the point of interpolation. Between 0 and 1, the linear interpolant will occur on a straight line between lhs and rhs. Outside of this range, the linear interpolant will occur on a ray extrapolated from this line.
Self for chaining.
const a = new pc.Color(0, 0, 0);
const b = new pc.Color(1, 1, 0.5);
const r = new pc.Color();
r.lerp(a, b, 0); // r is equal to a
r.lerp(a, b, 0.5); // r is 0.5, 0.5, 0.25
r.lerp(a, b, 1); // r is equal to b
Converts the color to string form. The format is '#RRGGBBAA', where RR, GG, BB, AA are the red, green, blue and alpha values. When the alpha value is not included (the default), this is the same format as used in HTML/CSS.
If true, the output string will include the alpha value.
The color in string form.
const c = new pc.Color(1, 1, 1);
// Outputs #ffffffff
console.log(c.toString());
Representation of an RGBA color.