# Cylinder pixel map

**URL:** <https://forum.electromage.com/t/cylinder-pixel-map/641>\
**Category:** Patterns and Code\
**Created:** [October 14, 2020, 8:53pm UTC](https://forum.electromage.com/t/cylinder-pixel-map/641 "2020-10-14T20:53:42Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![nickbeaulieu](https://forum.electromage.com/letter_avatar_proxy/v4/letter/n/ea5d25/32.png) [@nickbeaulieu](https://forum.electromage.com/u/nickbeaulieu)\
**Post date:** [October 14, 2020, 8:53pm UTC](https://forum.electromage.com/t/cylinder-pixel-map/641/1 "2020-10-14T20:53:43Z")

</div>

Hi all,

I’m trying to map a cylinder and I’m having a difficult time of it. I’m building a lamp that will have 18 rings with 17 LEDs on each ring. I seem to be having some difficulty designing it and was wondering if anyone could give me a hand?

Thanks,  
Nick

---

<div class="post-metadata">

**Author:** ![jeff](https://forum.electromage.com/user_avatar/forum.electromage.com/jeff/32/3473_2.png) [@jeff](https://forum.electromage.com/u/jeff)\
**Post date:** [October 14, 2020, 9:57pm UTC](https://forum.electromage.com/t/cylinder-pixel-map/641/2 "2020-10-14T21:57:50Z")

</div>

Sure! This map just builds off the pre-loaded “Ring” example.

I assumed each layered ring is wired sequentially, and that pixel index 0 is in the bottom layer.

```javascript
function (pixelCount) {
  var map = [];
  var layers = 18;
  var pixPerRing = 17;
  for (layer = 0; layer < layers; layer++) {
    for (i = 0; i < pixPerRing; i++) {
      c = i / pixPerRing * Math.PI * 2
      map.push([Math.cos(c), Math.sin(c), layer])
    }
  }
  return map
}

```

 ![Pixelblaze 2020-10-14 14-56-52](https://forum.electromage.com/uploads/default/original/1X/b18e2c6961b8a548a8b69a657209b38364f14d14.png)

---

<div class="post-metadata">

**Author:** ![nickbeaulieu](https://forum.electromage.com/letter_avatar_proxy/v4/letter/n/ea5d25/32.png) [@nickbeaulieu](https://forum.electromage.com/u/nickbeaulieu)\
**Post date:** [October 14, 2020, 10:00pm UTC](https://forum.electromage.com/t/cylinder-pixel-map/641/3 "2020-10-14T22:00:01Z")

</div>

oh, that’s amazing. Thanks!

---

<div class="post-metadata">

**Author:** ![Scruffynerf](https://forum.electromage.com/letter_avatar_proxy/v4/letter/s/34f0e0/32.png) [@Scruffynerf](https://forum.electromage.com/u/Scruffynerf)\
**Post date:** [October 14, 2020, 11:10pm UTC](https://forum.electromage.com/t/cylinder-pixel-map/641/4 "2020-10-14T23:10:24Z")

</div>

One caveat, the above assumes it’s wired around the same direction each time, and not zigzag. That bit me too, working on a similar mapping.

See [Manually adjusting spin in mapper?](https://forum.electromage.com/t/manually-adjusting-spin-in-mapper/640)

But I need to shift 1 for the zags, to get it right. This week, next time I get time to play. (It’s also top down, as well as zigzag). Hopefully between the two, we can have a good example. I’ll recraft mine to have variables for up/down and zigzag/continuous.

---

<div class="post-metadata">

**Author:** ![nickbeaulieu](https://forum.electromage.com/letter_avatar_proxy/v4/letter/n/ea5d25/32.png) [@nickbeaulieu](https://forum.electromage.com/u/nickbeaulieu)\
**Post date:** [October 19, 2020, 7:03pm UTC](https://forum.electromage.com/t/cylinder-pixel-map/641/5 "2020-10-19T19:03:35Z")

</div>

I have one issue and I guess I don’t understand the code enough to fix it. The first row only has 16 pixels on it, as I needed room for the wiring from the pixelblaze. Everything else is perfect. How would I adjust for this offset?

---

<div class="post-metadata">

**Author:** ![Scruffynerf](https://forum.electromage.com/letter_avatar_proxy/v4/letter/s/34f0e0/32.png) [@Scruffynerf](https://forum.electromage.com/u/Scruffynerf)\
**Post date:** [October 19, 2020, 9:34pm UTC](https://forum.electromage.com/t/cylinder-pixel-map/641/6 "2020-10-19T21:34:26Z")

</div>

Ah, it’s always the exceptions…

So layer 0 has only 16 pixels not 17?

Add this:

If (layer==0 && i==0){  
// Skip the first very spot, no pixel  
} else {  
map.push([Math.cos©, Math.sin©, layer])  
}

Around that map.push line. It’ll skip only the one spot.

(Sorry, on mobile, will edit for code later)

---

<div class="post-metadata">

**Author:** ![nickbeaulieu](https://forum.electromage.com/letter_avatar_proxy/v4/letter/n/ea5d25/32.png) [@nickbeaulieu](https://forum.electromage.com/u/nickbeaulieu)\
**Post date:** [October 19, 2020, 11:36pm UTC](https://forum.electromage.com/t/cylinder-pixel-map/641/7 "2020-10-19T23:36:29Z")

</div>

thanks, I appreciate it 😃 !

---

<div class="post-metadata">

**Author:** ![spazzle](https://forum.electromage.com/user_avatar/forum.electromage.com/spazzle/32/2874_2.png) [@spazzle](https://forum.electromage.com/u/spazzle)\
**Post date:** [October 22, 2020, 10:19pm UTC](https://forum.electromage.com/t/cylinder-pixel-map/641/8 "2020-10-22T22:19:47Z")

</div>

This is a different take on a cylinder, and I haven’t yet made this in pixelblaze, but I made a thing where I wrapped a pole in a single long line of LEDs (actually 7 attached strings). Since I wrapped it at a fixed number of pixels per loop (mostly) it lined up in an easily addressable way. It ends up as a long helix. The mapping is something like this:

> function (pixelCount) {  
> var map = ;  
> numloops=41  
> for (i = 0; i \< pixelCount; i++) {  
> c = i / pixelCount \* Math.PI \* 2\*numloops  
> map.push([Math.cos(c), Math.sin(c),i/pixelCount])  
> }  
> return map  
> }

 ![image](https://forum.electromage.com/uploads/default/original/1X/3be20b829ca68c24fcc45fba006c50e80caae372.png)

It probably is easier to do this than have a large number of small loops.

---

<div class="post-metadata">

**Author:** ![Scruffynerf](https://forum.electromage.com/letter_avatar_proxy/v4/letter/s/34f0e0/32.png) [@Scruffynerf](https://forum.electromage.com/u/Scruffynerf)\
**Post date:** [October 22, 2020, 10:27pm UTC](https://forum.electromage.com/t/cylinder-pixel-map/641/9 "2020-10-22T22:27:12Z")

</div>

Yup, that’s another variation, more of a helix than a matrix (where a row is all at the same height).

I’ll be sure and add that into my “comprehensive ring/helix” mapper. Thanks!

---

<div class="post-metadata">

**Author:** ![spazzle](https://forum.electromage.com/user_avatar/forum.electromage.com/spazzle/32/2874_2.png) [@spazzle](https://forum.electromage.com/u/spazzle)\
**Post date:** [October 22, 2020, 10:31pm UTC](https://forum.electromage.com/t/cylinder-pixel-map/641/10 "2020-10-22T22:31:28Z")

</div>

That is a bit deceptive due to the large number of loops I used in that one, it is a true helix where there is a continuous gradient of height. Here is an example with less loops.

![image](https://forum.electromage.com/uploads/default/original/1X/b8f7e9440de2e148ede81197b3b5e36799b95a89.png)

---

<div class="post-metadata">

**Author:** ![Scruffynerf](https://forum.electromage.com/letter_avatar_proxy/v4/letter/s/34f0e0/32.png) [@Scruffynerf](https://forum.electromage.com/u/Scruffynerf)\
**Post date:** [October 22, 2020, 11:20pm UTC](https://forum.electromage.com/t/cylinder-pixel-map/641/11 "2020-10-22T23:20:46Z")

</div>

Yes, but the difference between the two is just one thing: does a row maintain a consistent height (and then a drop/rise to the next row), or is it a gradient to the next level with each slightly higher or lower? Otherwise the math is the same.

---

<div class="post-metadata">

**Author:** ![nickbeaulieu](https://forum.electromage.com/letter_avatar_proxy/v4/letter/n/ea5d25/32.png) [@nickbeaulieu](https://forum.electromage.com/u/nickbeaulieu)\
**Post date:** [October 22, 2020, 11:31pm UTC](https://forum.electromage.com/t/cylinder-pixel-map/641/12 "2020-10-22T23:31:31Z")

</div>

thanks for posting that! the next one I do like this will most likely be a spiral and not a matrix… save myself the soldering 😛

---

<div class="post-metadata">

**Author:** ![spazzle](https://forum.electromage.com/user_avatar/forum.electromage.com/spazzle/32/2874_2.png) [@spazzle](https://forum.electromage.com/u/spazzle)\
**Post date:** [October 22, 2020, 11:48pm UTC](https://forum.electromage.com/t/cylinder-pixel-map/641/13 "2020-10-22T23:48:19Z")

</div>

True, but for me it is trivial to run a long single loop of leds (and occasionally inject voltage), and much more of a pain to wire up several small loops.

---

<div class="post-metadata">

**Author:** ![Scruffynerf](https://forum.electromage.com/letter_avatar_proxy/v4/letter/s/34f0e0/32.png) [@Scruffynerf](https://forum.electromage.com/u/Scruffynerf)\
**Post date:** [October 23, 2020, 12:02am UTC](https://forum.electromage.com/t/cylinder-pixel-map/641/14 "2020-10-23T00:02:00Z")

</div>

Oh completely understand. In my case, I inserted LEDs of a strand into a sheet of plastic (which was supposed to be used as core of a plastic lamp) so it was super easy to make a zigzag matrix of it, rather than any other method. Do whatever works, as doing the mapper afterward is pretty easy (and I’m trying to help make it easier)

I need to take a photo of that lamp, will post it as part of a pile of stuff I’m working on. My to-do list grows.

---

<div class="post-metadata">

**Author:** ![devoh](https://forum.electromage.com/letter_avatar_proxy/v4/letter/d/c5a1d2/32.png) [@devoh](https://forum.electromage.com/u/devoh)\
**Post date:** [October 23, 2020, 12:04am UTC](https://forum.electromage.com/t/cylinder-pixel-map/641/15 "2020-10-23T00:04:16Z")

</div>

Is this visualization done with Pixel Teleporter?

---

<div class="post-metadata">

**Author:** ![spazzle](https://forum.electromage.com/user_avatar/forum.electromage.com/spazzle/32/2874_2.png) [@spazzle](https://forum.electromage.com/u/spazzle)\
**Post date:** [October 23, 2020, 12:06am UTC](https://forum.electromage.com/t/cylinder-pixel-map/641/16 "2020-10-23T00:06:48Z")

</div>

The pixelblaze pixel mapper (in version 2.23)

---

<div class="post-metadata">

**Author:** ![spazzle](https://forum.electromage.com/user_avatar/forum.electromage.com/spazzle/32/2874_2.png) [@spazzle](https://forum.electromage.com/u/spazzle)\
**Post date:** [October 23, 2020, 12:25am UTC](https://forum.electromage.com/t/cylinder-pixel-map/641/17 "2020-10-23T00:25:11Z")

</div>

I was going to try to do a correct conical mapping for fun, but then I did a search for it, and found that the wizard had already done one AND had a nearly identical cylindrical mapping. Is there a place where various mappings can be found?

---

<div class="post-metadata">

**Author:** ![Scruffynerf](https://forum.electromage.com/letter_avatar_proxy/v4/letter/s/34f0e0/32.png) [@Scruffynerf](https://forum.electromage.com/u/Scruffynerf)\
**Post date:** [October 23, 2020, 2:43am UTC](https://forum.electromage.com/t/cylinder-pixel-map/641/18 "2020-10-23T02:43:07Z")

</div>

We’re in the midst of a reorganizing, and mapping is part of that. Searching the forum is your best bet for now. Hopefully by 2021, it’ll be easier to find a large selection of maps and flexible mapping code to solve most common setups.

---

<div class="post-metadata">

**Author:** ![JerryB](https://forum.electromage.com/letter_avatar_proxy/v4/letter/j/ccd318/32.png) [@JerryB](https://forum.electromage.com/u/JerryB)\
**Post date:** [November 5, 2020, 9:26pm UTC](https://forum.electromage.com/t/cylinder-pixel-map/641/19 "2020-11-05T21:26:41Z")

</div>

**warning: i’m new with no coding or mapping experience**

I’ve just started on a new project (Pineapple) that involves a cylinder which has 16 vertical strips with 14 pixels per strip wired in an up/down pattern. I’d like to map this so I can attempt (key word) to apply patterns that can a) travel up and down the cylinder, and b) travel clockwise and counter clockwise around the cylinder both vertical and diagonal (off-set).

I tried modifying some of the code above but failed miserably. I’m also not comprehending how the mapping code interacts with the pattern code so that the pattern matches the map.

Any advice or examples would be greatly appreciated.

 ![Cylinder](https://forum.electromage.com/uploads/default/original/1X/120ee3e362a46b0b3bba043c7f08da20ae9eb44a.jpeg)

---

<div class="post-metadata">

**Author:** ![Scruffynerf](https://forum.electromage.com/letter_avatar_proxy/v4/letter/s/34f0e0/32.png) [@Scruffynerf](https://forum.electromage.com/u/Scruffynerf)\
**Post date:** [November 5, 2020, 10:53pm UTC](https://forum.electromage.com/t/cylinder-pixel-map/641/20 "2020-11-05T22:53:57Z")

</div>

ok, so let’s break this down:

vertical strips, up and down… going around in a circle.

you could just call it a 2d map, and it’ll work fine… it’s a zig zag, left right left, if you turn the cylinder on it’s side. Right? Ah, no, it’s reversed, looking at the wires above, it’s up (right), left (down), and so on.

If you want it to be 3d, we can build a map for that, but I suspect the simple 2d map (16x14) will work for most of what you want… so long as it’s right/left/right… not left/right/left

[Next page](https://forum.electromage.com/t/cylinder-pixel-map/641.md?page=2)
