Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
This chapter took an in-depth look at drawing in a canvas. We began by discussing the coordinate system and the Canvas drawing model, and then we looked at drawing simple rectangles, specifying colors and transparencies, using gradients and patterns, and applying shadows.
Then we took a look at paths and subpaths, and stroking and filling. We also looked at the nonzero winding rule that Canvas uses when filling intersecting subpaths, and you saw how to put that knowledge to practical use by implementing cutouts.
Then we focused on drawing lines, and you learned how to draw true one-pixel-wide lines and how to draw lines that appear to be less than one pixel wide. You saw how to use lines to draw grids and axes, and you learned how to let users interactively draw lines with rubber bands. You also saw how to draw dashed lines, which are not explicitly supported by the Canvas context, and then you saw how to extend the Canvas context so that dashed lines are explicitly supported. Finally, we wrapped up the section on lines by looking at line caps and joins, which determines how the Canvas context draws line endpoints.