Hi folks,
A bit late to the party, but I had an unusual arrangement of 8x8 panels and needed to map them. I came up with this system, which should allow all kinds of arbitrary arrangements of these or other panels of any width, height, and including rotations!
function (pixelCount) {
//enable zigzag if every other LED row travels in reverse
//if they are all straight across, disable it
zigzag = true
//roate a point (x, y), along a center (cx, cy), by an angle in degrees
function rotate(cx, cy, x, y, angle) {
var radians = (Math.PI / 180) * angle,
cos = Math.cos(radians),
sin = Math.sin(radians),
nx = (cos * (x - cx)) + (sin * (y - cy)) + cx,
ny = (cos * (y - cy)) - (sin * (x - cx)) + cy;
return [nx, ny];
}
//create a set of coordinates for a matrix panel
// sized (w, h), rotated by an angle, and offset by (sx, sy)
function panel(w, h, sx, sy, angle) {
var x, x2, y, p, map = []
for (y = 0; y < h; y++) {
for (x = 0; x < w; x++) {
//for zigzag, flip direction every other row
if (zigzag && y % 2 == 1)
x2 = w - 1 - x
else
x2 = x
p = rotate((w-1)/2, (h-1)/2, x2, y, angle);
p[0] += sx
p[1] += sy
map.push(p)
}
}
return map;
}
//assemble one or more panels
var map = [];
map = map.concat(panel(8, 8, 0, 0, 0))
map = map.concat(panel(8, 8, 0, 8, 0))
map = map.concat(panel(8, 8, 8, 8, 0))
map = map.concat(panel(8, 8, 8, 0, 0))
return map
}
Here’s my funky panel map in action:
In this kind of setup:
1 4
2 3
The rotation is really only intended to work with 90° increments, it positions the panels from the top left corner before rotation along the center. However, these helper functions could be adapted for arbitrary angles and positioning.