HTML and CSS Reference
This may all seem pretty simple, but its actually quite powerful. You can now let the browser do all the hard work,
instead of bringing in large bitmap graphics that will incur longer load times for your end user. Keep in mind that if it's
a vector shape, you can more or less re-create it using the canvas element
Another feature of the canvas element is its ability to use gradients. Gradients are useful for filling in shapes from
one color to another or building on multiple color values in a stack. Gradients are widely used in many things online.
For the longest time developers and designers created and repeated a 1-pixel-wide strip of the gradient using CSS.
Now, with native gradient support on the canvas element, the browser can again handle the heavy lifting. This is
exceptionally important to note when a client hands you Photoshop documents and you need to re-create an exact
representation in the browser while minimizing the k-weight. Instead of bringing in bitmaps from the PSD, tell the
canvas to handle it. It can be somewhat time-consuming, but the end result is worth the wait. Gradients can be Linear
or Radial or have multiple color stops between 0 and 1.
The main difference between a linear and a radial gradient is where the gradient begins. Figure 4-4 displays the
visual difference between them.
Figure 4-4. The difference between a linear and a radial gradient
Listing 4-6 makes a linear gradient fill for the star shape in Figure 4-3 .
Listing 4-6. A Linear Gradient Fill Using Canvas