Reputation: 50497
I'm trying to draw a grid on a <canvas>
element with the ultimate goal of making a Go board.
For some reason the grid is looking stretched, with the lines being thicker than 1 pixel and the spacing being completely wrong. It doesn't even start in the (10,10)
position..
It would be great if someone could take a look at tell me what I'm doing wrong.
Upvotes: 18
Views: 51335
Reputation: 50497
I've found the problem. I was setting the dimensions of the <canvas>
using CSS, when you actually have to set the width and height attributes. This was causing it to be stretched/skewed.
var canvas = $('<canvas/>').attr({width: cw, height: ch}).appendTo('body');
Upvotes: 36
Reputation: 87271
Please try it outside jsfiddle, maybe jsfiddle is applying some linear transformation.
Also please make sure that you add 0.5 everywhere to both x and y coordinates. Alternatively, you can apply translate(0.5, 0.5) to shift all coordinates by half a pixel.
Upvotes: 1