The Essential Guide to HTML5

(Greg DeLong) #1

DICE GAME


in the frown example, will “finish off” the arc. The complete code is




Frown





Your browser doesn't support the HTML5 element canvas.



This produces the screen show in Figure 2-8.


Figure 2-8. The frown becomes a half-circle by adding ctx.closePath(); before ctx.stroke();


The closePath command is not always necessary, but its good practice to include it. Experiment here
and also look ahead to the drawing of the slingshot in Chapter 5 and the drawing of the hangman figure in
Chapter 9. If you want the path filled in, you use ctx.fill() in place of ctx.stroke(), which produces a
black, filled-in shape as shown in Figure 2-9. The complete code is



Free download pdf