Class Color_EX

Hierarchy

  • Color
    • Color_EX

Constructors

  • Create a new Color object.

    Parameters

    • Optional r: number | number[]

      The 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

      The value of the green component (0-1). Defaults to 0.

    • Optional b: number

      The value of the blue component (0-1). Defaults to 0.

    • Optional a: number

      The value of the alpha component (0-1). Defaults to 1.

    Returns Color_EX

Properties

_shaderData: Float32Array
a: number

The alpha component of the color.

b: number

The blue component of the color.

g: number

The green component of the color.

r: number

The red component of the color.

BLACK: Color

A constant color set to black [0, 0, 0, 1].

BLUE: Color

A constant color set to blue [0, 0, 1, 1].

CYAN: Color

A constant color set to cyan [0, 1, 1, 1].

GRAY: Color

A constant color set to gray [0.5, 0.5, 0.5, 1].

GREEN: Color

A constant color set to green [0, 1, 0, 1].

MAGENTA: Color

A constant color set to magenta [1, 0, 1, 1].

RED: Color

A constant color set to red [1, 0, 0, 1].

WHITE: Color

A constant color set to white [1, 1, 1, 1].

YELLOW: Color

A constant color set to yellow [1, 1, 0, 1].

Accessors

Methods

  • Returns a clone of the specified color.

    Returns

    A duplicate color object.

    Returns Color_EX

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

    Returns

    Self for chaining.

    Example

    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: Color

      A color to copy to the specified color.

    Returns Color

  • Reports whether two colors are equal.

    Returns

    True if the colors are equal and false otherwise.

    Example

    var a = new pc.Color(1, 0, 0, 1);
    var b = new pc.Color(1, 1, 0, 1);
    console.log("The two colors are " + (a.equals(b) ? "equal" : "different"));

    Parameters

    • rhs: Color

      The color to compare to the specified color.

    Returns boolean

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

    Returns

    Self for chaining.

    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 Color

  • Returns the result of a linear interpolation between two specified colors.

    Returns

    Self for chaining.

    Example

    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: Color

      The color to interpolate from.

    • rhs: 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 Color

  • Assign values to the color components, including alpha.

    Returns

    Self for chaining.

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

    • Optional a: number

      The value for the alpha (0-1), defaults to 1.

    Returns Color

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

    Returns

    The color in string form.

    Example

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

    Parameters

    • alpha: boolean

      If true, the output string will include the alpha value.

    Returns string