pc.Color
Representation of an RGBA color.
Summary
Properties
| a | The alpha component of the color. |
| b | The blue component of the color. |
| g | The green component of the color. |
| r | The red component of the color. |
Methods
| clone | Returns a clone of the specified color. |
| copy | Copies the contents of a source color to a destination color. |
| fromString | Set the values of the color from a string representation '#11223344' or '#112233'. |
| lerp | Returns the result of a linear interpolation between two specified colors. |
| set | Assign values to the color components, including alpha. |
| toString | Converts the color to string form. |
Details
Constructor
Color([r], [g], [b], [a])
Create a new Color object.
Parameters
| r | number, number[] | The 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. |
| g | number | The value of the green component (0-1). |
| b | number | The value of the blue component (0-1). |
| a | number | The value of the alpha component (0-1). |
Properties
Methods
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
| rhs | pc.Color | A color to copy to the specified color. |
Returns
pc.ColorSelf for chaining.
fromString(hex)
Set the values of the color from a string representation '#11223344' or '#112233'.
Parameters
| hex | string | 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. |
Returns
pc.ColorSelf for chaining.
lerp(lhs, rhs, alpha)
Returns the result of a linear interpolation between two specified colors.
var a = new pc.Color(0, 0, 0);
var b = new pc.Color(1, 1, 0.5);
var 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
Parameters
| lhs | pc.Color | The color to interpolate from. |
| rhs | pc.Color | The color to interpolate to. |
| alpha | number | 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. |
Returns
pc.ColorSelf for chaining.
set(r, g, b, [a])
Assign values to the color components, including alpha.
Parameters
| r | number | The value for red (0-1). |
| g | number | The value for blue (0-1). |
| b | number | The value for green (0-1). |
| a | number | The value for the alpha (0-1), defaults to 1. |
Returns
pc.ColorSelf for chaining.
toString(alpha)
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.
var c = new pc.Color(1, 1, 1);
// Should output '#ffffffff'
console.log(c.toString());
Parameters
| alpha | boolean | If true, the output string will include the alpha value. |
Returns
stringThe color in string form.