Gradients

In this chapter you will learn:

  1. How to control the gradients

Set gradients

We can set the fill and stroke styles using gradients. The canvas element supports two kinds of gradients: linear and radial.

NameDescriptionReturns
createLinearGradient(x0, y0, x1, y1)Creates a linear gradientCanvasGradient
createRadialGradient(x0, y0, r0, x1, y1, r1)Creates a radial gradientCanvasGradient

CanvasGradient object defines the method shown in the following table:

NameDescriptionReturns
addColorStop(position, color)Adds a solid color to the gradient linevoid

Next chapter...

What you will learn in the next chapter:

  1. How to use the linear gradient
  2. Linear Gradient with a Smaller Shape
Home » Javascript Tutorial » Canvas
Canvas tag
Canvas Context
Rectangle
Rectangle clear
Drawing State
Drawing state restore
Line width
Line Join Style
Line cap settings
Gradients
Linear Gradient
Radial Gradient
Path
Arcs
Two types of curve
Quadratic Bezier Curves
Cubic Bezier Curves
Clip
Text
Shadow
Transparency
Stoke style