Javascript examples for Canvas Reference:rotate
The rotate() method rotates the current drawing.
context.rotate(angle);
Parameter | Description |
---|---|
angle | The rotation angle, in radians. |
To calculate from degrees to radians: degrees*Math.PI/180.
To rotate 5 degrees, specify the following: 5*Math.PI/180
Rotate the rectangle 20 degrees:
<!DOCTYPE html> <html> <body> <canvas id="myCanvas" width="300" height="250" style="border:1px solid #d3d3d3;"> Your browser does not support the HTML5 canvas tag.</canvas> <script> var c = document.getElementById("myCanvas"); var ctx = c.getContext("2d"); ctx.rotate(20 * Math.PI / 180);//from w w w .j ava 2 s.c o m ctx.fillRect(50, 20, 100, 100); </script> </body> </html>