Canvas Transformations part 2

HTML Fundamentals
HTML5
Canvas Transformations
20
2/3
               

The rotate() Method



The rotate() method is used to rotate the HTML5 Canvas. The value must be in radians, not degrees.

Here is an example that draws the same rectangle before and after rotation is set:
ctx.fillStyle = "#FF0000";
ctx.fillRect(10,10, 100, 100);

ctx.rotate( (Math.PI / 180) * 25); //rotate 25 degrees.

ctx.fillStyle = "#0000FF";
ctx.fillRect(10,10, 100, 100);
Try It Yourself


The rotation will only affect drawings made after the rotation is done.

Comments

Popular posts from this blog

Drag&Drop API