Noob guide to creating "mirrored" patterns in single string of WS2811?

What is the key to creating a “mirrored” pattern in PB - one that is symmetrical on either side of the center of the string? I see that there are several posted in the Patterns listings, and the centerpoint would be easy to find but how do you create a pattern that is “reflected” as these are? I think I’m missing something that’s obvious…

Basically, in your render() function, you do the same thing for each half of the LED strip, but the second half is mathematically reversed.

Here’s the simplest example I can come up with. The first and last pixels should be off, and the middle two pixels will be full-on. I assigned different colors to the two cases so you can see which is which.

middle = floor(pixelCount/2) - 1

export function render(index) {
  if(index <= middle) {
    value = index / middle // a number [0..1]
    hue = 0 // red
  } else {
    value = (index - middle - 1) / (pixelCount - middle) // a number [1..0]
    hue = 0.5 // cyan
  }

  hsv(hue,1,value)
}

Of course I haven’t tested it but I think I got all the fencepost logic in the right place!

1 Like

Thanks for this!

I’ve done some mapping that’s very similar using Arduino platforms and I think my hangup with Pixelblaze has been assuming that using particular pixel/LED involves “chaining” it all the way up the string - with the command being rendered and the LED showing as it goes - rather than being effectively rendered/shown just once as the data arrives at the target LED.

On to other errors…

Thanks again