🔰gradients

browsercanvasgraphics statefill/stroke styles ⟩ gradient

To fill (or stroke) with a gradient, set .fillStyle (or .strokeStyle) to a CanvasGradient object returned by: .createLinearGradient(), .createRadialGradient(), .createConicGradient().

after creating CanvasGradient object, define gradient colors by calling CanvasGradient.addColorStop() (at least twice), parameters:

The arguments to .createRadialGradient(): centers & radii of two circles:

  • need not be concentric.

  • first circle typically lies entirely inside the second.

  • areas inside smaller circle or outside the larger are filled with solid colors.

Gradient coordinates are relative to the drawing (2D) context, NOT relative to a shape's local coordinates.

Last updated