I'm trying to translate a "shape" (set of relative coordinates for four squares) to a pixel grid:
var grid_center = 6;
var square_size = 20;
l_shape = {
coords: [[-1, 0], [0, 0], [1, 0], [-1, 1]]
}
function draw_shape(shape, grid_location) {
for (coord in shape.coords) {
trans_coord = (grid_location[0] + coord[0]) * square_size;
console.log(trans_coord);
}
}
draw_shape(l_shape, [grid_center - 1, 0]);
Expected output:
100
120
140
160
Actual output:
1000
1020
1040
1060
Looks like it could be automatic type conversion weirdness, but I don't see how. All of my numbers are actual numbers, none quoted as strings. When entering the math manually, I get the expected result:
> (5 + 0) * 20
100
There may be better ways to do this from a computer science perspective, but I'm not interested in those. I just want to find out why the program above doesn't work as intended.