createLinearGradient method

CanvasGradient createLinearGradient(
  1. num x0,
  2. num y0,
  3. num x1,
  4. num y1,
)

The CanvasRenderingContext2D.createLinearGradient() method of the Canvas 2D API creates a gradient along the line connecting two given coordinates.

The gradient transitions colors along the gradient line, starting at
point x0, y0 and going to x1, y1, even if those points extend the gradient
line beyond the edges of the element on which the gradient is
drawn.

This method returns a linear CanvasGradient. To be applied to a shape, the gradient must first be assigned to the CanvasRenderingContext2D.fillStyle or CanvasRenderingContext2D.strokeStyle properties.

Note: Gradient coordinates are global, i.e., relative to the current coordinate space. When applied to a shape, the coordinates are NOT relative to the shape's coordinates.

Implementation

external CanvasGradient createLinearGradient(
  num x0,
  num y0,
  num x1,
  num y1,
);