# 9 panel array Mapper not visualizing correctly

**URL:** <https://forum.electromage.com/t/9-panel-array-mapper-not-visualizing-correctly/3400>\
**Category:** Troubleshooting\
**Tags:** mapping, beginner, v3\
**Created:** [January 30, 2024, 9:05pm UTC](https://forum.electromage.com/t/9-panel-array-mapper-not-visualizing-correctly/3400 "2024-01-30T21:05:05Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![gingerbeardman](https://forum.electromage.com/user_avatar/forum.electromage.com/gingerbeardman/32/3321_2.png) [@gingerbeardman](https://forum.electromage.com/u/gingerbeardman)\
**Post date:** [January 30, 2024, 9:05pm UTC](https://forum.electromage.com/t/9-panel-array-mapper-not-visualizing-correctly/3400/1 "2024-01-30T21:05:05Z")

</div>

Hello!

I’m running into an issue trying to use PixelBlaze to run 9 panels in a 3x3 grid. Each of these panels has 100 LEDs. ZigZag configuration.

I can get the visualizer to display the first 3 sets of panels. However any of the others I can not. Using the offset value in the panel section in order to try and see the setup. I’m still working on my panels, so I can’t physically see yet if it is just the visualizer.

I set the LED count to 900 in Settings.

Here is the code, built upon the provided example code for “Multiple Panel Matrix”

```auto
function (pixelCount) {
  //set zigzag to true if every other LED row travels in reverse
  //if they are all straight across, set it to false
  zigzag = true
  
  
  //rotate 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[.5] += sy
        map.push(p)
      }
    }
    return map;
  }

  //assemble one or more panels
  var map = [];

  map = map.concat(panel(10, 10, 0, 0, 90))
  map = map.concat(panel(10, 10, 10, 0, 90))
  map = map.concat(panel(10, 10, 20, 0, 90))
  
  map = map.concat(panel(10, 10, 0, 10, 90))
  map = map.concat(panel(10, 10, 10, 10, 90))
  map = map.concat(panel(10, 10, 20, 10, 90))
  
  map = map.concat(panel(10, 10, 0, 20, 90))
  map = map.concat(panel(10, 10, 10, 20, 90))
  map = map.concat(panel(10, 10, 20, 20, 90))
  
  return map
}

```

Any help is much appreciated. First time Pixel Blazer and Portland Winter Lights Festival participant.

---

<div class="post-metadata">

**Author:** ![sorceror](https://forum.electromage.com/user_avatar/forum.electromage.com/sorceror/32/735_2.png) [@sorceror](https://forum.electromage.com/u/sorceror)\
**Post date:** [January 31, 2024, 2:45pm UTC](https://forum.electromage.com/t/9-panel-array-mapper-not-visualizing-correctly/3400/2 "2024-01-31T14:45:36Z")

</div>

I ran your code in my browser console (pasted with the first line as `function foo(pixelCount) {` then ran `foo(900)`) and the results are a bit crazy. Where did the `p[.5]` in your code come from? Here’s a slice of the results:

```javascript
6 : (2) [0, 3, 0.5: NaN]
7 : (2) [0, 1.9999999999999996, 0.5: NaN]
8 : (2) [0, 0.9999999999999996, 0.5: NaN]
9 : (2) [0, 0, 0.5: NaN]

```

Instead of `rotate()`, I would swap x and y.

I suspect that you can only see 3 sets of panels because the other 2 are in the same location 😃

---

<div class="post-metadata">

**Author:** ![wizard](https://forum.electromage.com/user_avatar/forum.electromage.com/wizard/32/4_2.png) [@wizard](https://forum.electromage.com/u/wizard)\
**Post date:** [January 31, 2024, 4:47pm UTC](https://forum.electromage.com/t/9-panel-array-mapper-not-visualizing-correctly/3400/3 "2024-01-31T16:47:56Z")

</div>

It is the half-element index that is getting you!

Otherwise that code is the stock “Multiple Panel Matrix” code and should work just fine for this.

Line

```auto
p[.5] += sy

```

should be reverted back to

```auto
p[1] += sy

```

The `p` variable here is a 2 element array that represents the pixel point, which would have a valid index of 0 for X and 1 for Y. The `sy` is the panel Y offset. By changing the `[1]` index it’s not longer applying the `sy` to the pixel’s Y coordinate, and that causes all of the panels to end up overlapping.

With that one fix, your 9 panels appear to map properly in a large grid.

 ![Screenshot 2024-01-31 at 8.46.09 AM](https://forum.electromage.com/uploads/default/original/2X/d/d390743a718660d63ff5a4a6858d6d84e9f76a20.jpeg)

Did you need to offset something by half a pixel? That’s possible.

---

<div class="post-metadata">

**Author:** ![gingerbeardman](https://forum.electromage.com/user_avatar/forum.electromage.com/gingerbeardman/32/3321_2.png) [@gingerbeardman](https://forum.electromage.com/u/gingerbeardman)\
**Post date:** [February 1, 2024, 5:05am UTC](https://forum.electromage.com/t/9-panel-array-mapper-not-visualizing-correctly/3400/4 "2024-02-01T05:05:37Z")

</div>

Ya I believe that, I have been kind of guessing some of what the variables mean… dangerous game I know. lol

As Wizard has stated below, I have a staggered offset in my LED panels, so was trying to guess where to edit that. I’ll take a picture of it once I finish soldering.

Thanks for the reply!

---

<div class="post-metadata">

**Author:** ![gingerbeardman](https://forum.electromage.com/user_avatar/forum.electromage.com/gingerbeardman/32/3321_2.png) [@gingerbeardman](https://forum.electromage.com/u/gingerbeardman)\
**Post date:** [February 1, 2024, 5:10am UTC](https://forum.electromage.com/t/9-panel-array-mapper-not-visualizing-correctly/3400/5 "2024-02-01T05:10:10Z")

</div>

Awesome! I figured I had missed something pretty obvious (if I knew what I was doing). That being said, this has been a phenomenal experience and color me thoroughly impressed, in whatever color hex code that would be.

And yes, I do I was attempting to offset each zig-zagged strip “column” by a half pixel. I’ll take a photo too of my fabricated panels and post it soon, but it seems like you understand what I mean.

---

<div class="post-metadata">

**Author:** ![wizard](https://forum.electromage.com/user_avatar/forum.electromage.com/wizard/32/4_2.png) [@wizard](https://forum.electromage.com/u/wizard)\
**Post date:** [February 1, 2024, 5:48pm UTC](https://forum.electromage.com/t/9-panel-array-mapper-not-visualizing-correctly/3400/6 "2024-02-01T17:48:38Z")

</div>

> [@gingerbeardman](#):
>
> `if (zigzag && y % 2 == 1)`

This is the condition test for a zigzag line. The `y % 2 == 1` is testing for odd rows. The line after the `else` happens for even rows.

Keep in mind the rows/columns and x,y terminology for zigzag is oriented before rotation, and the position (sx, sy) happens after rotation. I think you want to offset rows left or right long the x axis, and after rotation it would be a vertical shift.

What you might do is then add a little to `x2` for the zigzag rows. Try changing this line

```auto
x2 = w - 1 - x

```

to

```auto
x2 = w - 1 - x + 0.5

```

---

<div class="post-metadata">

**Author:** ![gingerbeardman](https://forum.electromage.com/user_avatar/forum.electromage.com/gingerbeardman/32/3321_2.png) [@gingerbeardman](https://forum.electromage.com/u/gingerbeardman)\
**Post date:** [February 5, 2024, 8:45pm UTC](https://forum.electromage.com/t/9-panel-array-mapper-not-visualizing-correctly/3400/7 "2024-02-05T20:45:17Z")

</div>

Thanks again for the help!

Since you both helped me out getting this correctly up and running, thought I’d share the results from this project album:

[[35 new items added to shared album] Deepsea Dazed & Diffused: CETI -... ![](https://lh3.googleusercontent.com/pw/ABLVV87lPFYlIAtWebAR-UpTDCOp6_4WyeAF672IXtqSSKN6MwkGYpFY4-Wz6CtnFsFw2TDwRxKyf3VwMi5b5tpbVUlxPdzO-Iz_25_2VSvyh2ESagk5XXf_=w600-h315-p-k "Deepsea Dazed & Diffused: CETI - Constellations - Portland Winter Lights...") ](https://photos.app.goo.gl/7Ru2cX16tGwzVBvw5)

---

<div class="post-metadata">

**Author:** ![gingerbeardman](https://forum.electromage.com/user_avatar/forum.electromage.com/gingerbeardman/32/3321_2.png) [@gingerbeardman](https://forum.electromage.com/u/gingerbeardman)\
**Post date:** [February 5, 2024, 8:46pm UTC](https://forum.electromage.com/t/9-panel-array-mapper-not-visualizing-correctly/3400/8 "2024-02-05T20:46:14Z")

</div>

Thanks again for the help!

You and Wizard helped me out getting this correctly up and running, so I thought I’d share the results from this project album:

[[35 new items added to shared album] Deepsea Dazed & Diffused: CETI -... ![](https://lh3.googleusercontent.com/pw/ABLVV87lPFYlIAtWebAR-UpTDCOp6_4WyeAF672IXtqSSKN6MwkGYpFY4-Wz6CtnFsFw2TDwRxKyf3VwMi5b5tpbVUlxPdzO-Iz_25_2VSvyh2ESagk5XXf_=w600-h315-p-k "Deepsea Dazed & Diffused: CETI - Constellations - Portland Winter Lights...") ](https://photos.app.goo.gl/7Ru2cX16tGwzVBvw5)

---

<div class="post-metadata">

**Author:** ![wizard](https://forum.electromage.com/user_avatar/forum.electromage.com/wizard/32/4_2.png) [@wizard](https://forum.electromage.com/u/wizard)\
**Post date:** [February 6, 2024, 5:43pm UTC](https://forum.electromage.com/t/9-panel-array-mapper-not-visualizing-correctly/3400/9 "2024-02-06T17:43:51Z")

</div>

Very cool! Great work on that project. I love the diffuser/panel design and organic look!

---

<div class="post-metadata">

**Author:** ![system](https://forum.electromage.com/uploads/default/original/1X/98123d16088a5451b5a585e24c0f2a40dd76061e.png) [@system](https://forum.electromage.com/u/system)\
**Post date:** [June 5, 2024, 5:43pm UTC](https://forum.electromage.com/t/9-panel-array-mapper-not-visualizing-correctly/3400/10 "2024-06-05T17:43:54Z")

</div>

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.
