HTML canvas rotate()Method
Examples
Rotate the rectangle by 20 degrees:
JavaScript:
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.rotate(20*Math.PI/180);
ctx.fillRect(50,20,100,50);
var ctx=c.getContext("2d");
ctx.rotate(20*Math.PI/180);
ctx.fillRect(50,20,100,50);
Try it Yourself »
Browser Support
![]()
![]()
![]()
![]()
![]()
Internet Explorer 9, Firefox, Opera, Chrome, and Safari support the rotate() method.
Note:Internet Explorer 8 and earlier versions do not support the <canvas> element.
Definition and Usage
The rotate() method rotates the current drawing.
Note:The rotation only affects the drawing that is done after the rotation.
| JavaScript Syntax: | context.rotate(angle); |
|---|
Parameter Values
| Parameter | Description |
|---|---|
| angle | The rotation angle, in radians. If you need to convert degrees to radians, usedegreesthe *Math.PI/180 formula to calculate. Example: To rotate 5 degrees, specify the following formula: 5*Math.PI/180. |
Other Extensions
Canvas Object