Skip to content

Instantly share code, notes, and snippets.

@gallaugher
Created September 25, 2025 22:41
Show Gist options
  • Save gallaugher/b0792bcd628d115c18c6ad436e1a2cc4 to your computer and use it in GitHub Desktop.
Save gallaugher/b0792bcd628d115c18c6ad436e1a2cc4 to your computer and use it in GitHub Desktop.
Improved Matrix Mapper Code
// Improved Matrix Mapper Code
function (pixelCount) {
width = 16 // width of LED panel
angle = 90 // rotation in degrees: 0, 90, 180, 270
flip = true // does the rendering need to be flipped?
height = width/pixelCount
map = []
for (i = 0; i < pixelCount; i++) {
y = Math.floor(i / width)
x = i % width
x = y % 2 == 1 ? width - 1 - x : x //zigzag
map.push([x, y])
}
if (flip) {
for (i = 0; i < map.length; i++) {
map[i][0] = (width - 1) - map[i][0]; // mirror X
}
}
// helper: apply 90°-step rotation
function rotate90(x, y, angle) {
if (angle === 90) return [y, width - 1 - x]
if (angle === 180) return [width - 1 - x, height - 1 - y]
if (angle === 270) return [height - 1 - y, x]
return [x, y] // 0° or default
}
// apply rotation of angle
for (i = 0; i < map.length; i++) {
p = rotate90(map[i][0], map[i][1], angle)
map[i][0] = p[0]
map[i][1] = p[1]
}
return map
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment