var gradient = createLinearGradient( startX, startY, endX, endY )
gradient.addColorStop(gradientPercentPosition, CssColor)
gradient.addColorStop(gradientPercentPosition, CssColor)
[optionally add more color stops to add to the variety of the gradient]
Creates a reusable linear gradient (object).
The object can be assigned to any strokeStyle
and/or fillStyle
.
Then stroke() or fill() will color the Path with the gradient colors of the object.
Creating a gradient object is a 2-step process:
var gradient = context.createLinearGradient
.gradient.addColorStop
.Arguments:
gradientPercentPosition
.gradientPercentPosition
.The gradient object is an object that you can use (and reuse!) to make your path strokes and fills become gradient colored.
Side Note: The gradient object is not internal to the Canvas element nor it’s Context. It is a separate and reusable JavaScript object that you can assign to any Path you desire. You can even use this object to color a Path on a different Canvas element(!)
Color stops are (percentage) waypoints along the gradient line. At each color stop waypoint, the gradient is fully (==opaquely) colored with it’s assigned color. Interim points along the gradient line between color stops are colored as gradients of the this and the previous color.
Important hint about Canvas gradients!
When you create a gradient object, the entire canvas is “invisibly” filled with that gradient.