Hi all. How would I map rings that are stacked on top of each other? I have 7 identical rings that I want to stack on top of each other, but I don’t quite know how to map it

```
function (pixelCount) {
var ringSize = 16
var map = [];
for (i = 0; i < pixelCount; i++) {
c = i / pixelCount * Math.PI * 2 * (pixelCount/ringSize)
map.push([Math.cos(c), Math.sin(c), Math.floor((i)/ringSize)])
}
return map
}
```

I believe this will do what you’re looking for. As long as your pixelCount is a multiple of your ringSize.

The above code sets the z value equal to i (which changes 0 to pixelCount-1) divided by ringsize

This means z varies, in slow spiral upward.

Let’s say ringsize is 16

from 0, 1/16, 2/16,3/16 etc. So it’s a small rise.

At 16/16, it’s 1, and so on…

This gets renormalized, but the end result is still a spiral rise from the bottom.

This is more a long string of lights than flat rings.

For rings, flatten that math, by rounding down.

So use `floor()`

on it. Then only the whole number is used, so it’s zero, zero, zero, then one, one, one, etc

Edit: the code has floor correctly. My brain didn’t see it. But hopefully the above is clear why floor(i/ringsize) works.

I hear what you’re saying but not sure how to implement your suggestion

I’m not seeing where another floor is needed. But I also don’t quite understand how the mapper works so I’m assuming I’m missing something.

If I just mentally go through the function, I get z as only whole integers.

For i = 0, z = floor(0/16) = 0

For i = 1, z = floor(1/16) = 0

For i = 17, z = floor(17/16) = 1

For i = 18, z = floor (18/16) = 1

I do see why it needs to be `floor((i+1)/ringSize)`

, though.

Sigh, I’m a goof and misread it as not having a floor the first time. Never mind. I glanced at the code and if I’d bothered to cut and paste, I’d have seen it had the floor already. My bad.

But it doesn’t need to be i+1, that’ll shift it wrong, ring 1 would 0-15, so pixel 16 would be ring 2… Etc.

I swear, 90% of my programming problems are trying to compensate for 0-indexed things when I don’t need to.

We all do it… 90% of all programming is debugging the mistakes you make.

Have you heard this one?

There’s only two hard things in computer science:

- Naming things
- Cache invalidation
- Off-by-one errors

There’s only 10 kinds of programmers; those who think in binary and those who don’t.