November 2011
Intermediate to advanced
348 pages
7h 2m
English
The next type of transformation available with the HTML5 canvas API, and quite arguably the handiest, is the rotation transform. In this recipe, we'll first position the canvas context with a translation transform, and then we'll rotate the context with rotate() method.

Follow these steps to draw a rotated rectangle:
window.onload = function(){
var canvas = document.getElementById("myCanvas");
var context = canvas.getContext("2d");
var rectWidth = 150;
var rectHeight = 75;// translate ...
Read now
Unlock full access