November 2011
Intermediate to advanced
348 pages
7h 2m
English
In this recipe, we'll learn how to perform the most basic and commonly used transformation available with the HTML5 canvas API—translation. If you're unfamiliar with transformation terminologies, "translation" is just a fancy way of saying "move". In this case, we'll be moving the context to a new location on the canvas.

Follow these steps to draw a translated rectangle moved to the center of the canvas:
window.onload = function(){ var canvas = document.getElementById("myCanvas"); var context = canvas.getContext("2d"); var rectWidth = 150; ...Read now
Unlock full access