Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grid drawn using a <canvas> element looking stretched

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.

http://jsfiddle.net/h2yJn/

alt text

like image 533
Acorn Avatar asked Nov 13 '10 11:11

Acorn


1 Answers

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');

http://jsfiddle.net/h2yJn/66/

alt text

like image 192
Acorn Avatar answered Oct 11 '22 21:10

Acorn