Retrieving the 2D Context

Finally, we need to get a reference to the 2D context so that we can manipulate it. HTML5 Canvas is designed to work with multiple contexts, including a proposed 3D context. However, for the purposes of this book, we need to get only the 2D context:

var context = theCanvas.getContext("2d");

Get HTML5 Canvas, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.