I have an object of pixel map, each row contains an object of columns, that contains a colour information. Then I choose the colour using switch()
, and then I simply draw it to canvas. Here is the code:
for(var pixX in pixmap) {
for(var pixY in pixmap[pixX]) {
switch(pixmap[pixX][pixY]) {
case 1: var pixColor='lightgray'; break;
case 2: var pixColor='black'; break;
default: var pixColor='forestgreen'; break;
}
$('canvas#surface').drawRect({
fillStyle: pixColor,
width: 1, height: 1,
x: pixX, y: pixY,
fromCenter: false
});
}
}
It draws the pixels, but the pixel position is somehow zoomed, although, the pixels are really just 1px big. I can't determine, how much it zooms. When I draw after a while to the canvas, the position is correct. What's the problem?
Edit: I've recreated it on jsFiddle: http://jsfiddle.net/qyNTn/