Represents a linear, uniform color gradient.

Constructors

Properties

Methods

Constructors

  • Define a new linear color gradient using an array of color stops. Gradients can include any number of color stops, which are all equally spaced from one another.

    Parameters

    • colors: Color[]

      An array of colors to define this color gradient

    Returns Gradient

    const redBlue = new Gradient([
    new Color(255, 0, 0),
    new Color(0, 0, 255),
    ]);

Properties

colors: Color[]

An array of colors to define this color gradient

Methods

  • Linearly interpolate between color stops to get a color along this gradient.

    Parameters

    • x: number

      A value between min, max to use for selecting a color along this gradient. An x value of min will select the first color stop, and an x value of max will select the last color stop. If min and max are not present, x should be a normalized value.

    • min: number = 0

      The minimum range of the color scale

    • max: number = 1

      The maximum range of the color scale

    Returns Color

    The interpolated color

    const myColor = redBlue.getColor(0.5);
    // Returns interpolated color (127.5, 0, 127.5)
  • Return a string representation of this gradient.

    Parameters

    • deg: number = 90

      The direction of this color gradient, in degrees

    Returns string

    A valid CSS color gradient

    const str = redBlue.toString(180);
    // linear-gradient(180deg,rgba(255,0,0,100%),rgba(0,0,255,100%))
MMNEPVFCICPMFPCPTTAAATR