25.02.2013 Views

Peter Lubbers - Pro HTML 5 Programming

Pro HTML 5 Programming

Pro HTML 5 Programming

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Figure 2-15. Tree with a larger scale<br />

CHAPTER 2 ■ USING THE <strong>HTML</strong>5 CANVAS API<br />

ALWAYS PERFORM SHAPE AND PATH ROUTINES AT THE ORIGIN<br />

Brian says (and really means it, this time): “This example illustrates one of the reasons why it is a good<br />

idea to perform shape and path routines at the origin; then translate them when complete, as we do here<br />

in our code. The reason is that transforms such as scale and rotate operate from the origin.<br />

If you perform a rotate transform to a shape drawn off origin, a rotate transform will rotate the shape<br />

around the origin rather than rotating in place. Similarly, if you performed a scale operation to shapes<br />

before translating them to their proper position, all locations for path coordinates would also be multiplied<br />

by the scaling factor. Depending on the scale factor applied, this new location could even be off the canvas<br />

altogether, leaving you wondering why your scale operation just ‘deleted’ the image.”<br />

51

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!