rotation test

canvas test create pale grid rotate and recreate grid from center

by rob Davis

HTML

<body>
    <canvas id="myCanvas" width="578" height="500"></canvas>
  </body>

CSS

body {
        margin: 0px;
        padding: 0px;
      }

JavaScript

var canvas = document.getElementById('myCanvas');
var context = canvas.getContext('2d');

var width = 500;
var height = 500;

drawGrid(width,height,'#f0f0f0');
context.translate(width/2,height/2);
context.rotate(deg2Rad(15));
drawGrid(width,height,'#ff0000');

function drawGrid(w,h,style)
{
    context.beginPath();
    var x=0;
    var y=0;
    for (y=0;y<h;y+=(h*.1)){
            context.moveTo(x, y);
            context.lineTo(w, y);
    }
    y=0;
    for (var x=0;x<w;x+=(w*.1)){
            context.moveTo(x, y);
            context.lineTo(x, h);
    }
    context.fillStyle=style;
    context.fillRect(0,0,w*0.1,h*0.1);
    context.fill();
    //context.lineWidth = 7;
    context.strokeStyle=style;
    context.stroke();
}

function deg2Rad(deg){
    return deg*Math.PI/180;
}