API Reference

Class List

pc.Color

Representation of an RGBA color

Summary

Properties

aThe alpha component of the color
bThe blue component of the color
gThe green component of the color
rThe red component of the color

Methods

cloneReturns a clone of the specified color.
copyCopies the contents of a source color to a destination color.
fromStringSet the values of the color from a string representation '#11223344' or '#112233'.
setAssign values to the color components, including alpha
toStringConverts the color to string form.

Details

Constructor

Color([r], [g], [b], [a])

Create a new Color object

Parameters

rNumberThe value of the red component (0-1). If r is an array of length 3 or 4, the array will be used to populate all components.
gNumberThe value of the green component (0-1)
bNumberThe value of the blue component (0-1)
aNumberThe value of the alpha component (0-1)

Properties

Numbera

The alpha component of the color

Numberb

The blue component of the color

Numberg

The green component of the color

Numberr

The red component of the color

Methods

clone()

Returns a clone of the specified color.

Returns

pc.Color A duplicate color object

copy(rhs)

Copies the contents of a source color to a destination color.

var src = new pc.Color(1, 0, 0, 1);
var dst = new pc.Color();

dst.copy(src);

console.log("The two colors are " + (dst.equals(src) ? "equal" : "different"));

Parameters

rhspc.ColorA color to copy to the specified color.

Returns

pc.Color Self for chaining

fromString(hex)

Set the values of the color from a string representation '#11223344' or '#112233'.

Parameters

hexStringA 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.

Returns

pc.Color Self for chaining

set(r, g, b, [a])

Assign values to the color components, including alpha

Parameters

rNumberThe value for red (0-1)
gNumberThe value for blue (0-1)
bNumberThe value for green (0-1)
aNumberThe value for the alpha (0-1), defaults to 1

Returns

pc.Color Self for chaining

toString()

Converts the color to string form. The format is '#RRGGBBAA', where RR, GG, BB, AA are the red, green, blue and alph values. When the alpha value is not included (the default), this is the same format as used in HTML/CSS.

var c = new pc.Color(1, 1, 1);
// Should output '#ffffffff'
console.log(c.toString());

Returns

String The color in string form.