# Am I Mapping Properly?

**URL:** <https://forum.electromage.com/t/am-i-mapping-properly/4247>\
**Category:** Uncategorized\
**Created:** [September 25, 2025, 10:47pm UTC](https://forum.electromage.com/t/am-i-mapping-properly/4247 "2025-09-25T22:47:01Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gallaugher](https://forum.electromage.com/user_avatar/forum.electromage.com/gallaugher/32/3889_2.png) [@Gallaugher](https://forum.electromage.com/u/Gallaugher)\
**Post date:** [September 25, 2025, 10:47pm UTC](https://forum.electromage.com/t/am-i-mapping-properly/4247/1 "2025-09-25T22:47:01Z")

</div>

I have a 16x16 NeoPixel-style Matrix & when I print one pixel after another my pattern is serpentine from upper left down/up/down, ending at upper right.  
The Matrix Mapper’s default doesn’t seem to work for this pattern.  
I wanted to write a more flexible default that could be tweaked depending on the layout of lights in a given matrix. Did I do this right?  
**[Improved Matrix Mapper Code · GitHub](https://bit.ly/pixelblaze-matrix-mapper)**

Please advise if I have any of this wrong, I’m doing something “non-standard” or I’m over complicating things.  
Full code here:

```auto
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
}

```
