Hey @kissay!
Thanks sorceror for the 2D solution! I’ll offer one for the 1D patterns.
Over half the default patterns are 1D patterns. You can identify them because they display a [1D] in the top left when you run them, even when a map is provided. They are patterns that don’t have an export function render2D()
line, only an export function render()
line.
These patterns depend heavily on the index
variable, which is just the position of that pixel in the strip. It starts with index 0, so the third pixel’s index
is 2
. To fix these patterns, we won’t use the map; we’ll decide how to transform the indices of your second, shorter run (the “inner rainbow”) that is reverse to the first.
Lots of “1D” patterns are written with some waves that repeat every 5-30 pixels. For these, things would look good if we flip the indices for the second, inner arc. To flip them, we want to find some function we can copy-paste just inside the export function rendex(index) {}
part that will transform them like this:
This index |
Becomes this |
0 |
0 |
249 |
249 |
250 |
349 |
349 |
250 |
We’ll also want pixelCount to be either 250 or 150 for that arc.
The code to do that is this:
if (index > 249) {
index = 599 - index
pixelCount = 150
} else {
pixelCount = 250
}
For each 1D pattern you want to adapt, you’ll need to copy-paste that inside render()
at the top like this:
For example, with the built-in pattern “marching rainbow”:
export function render(index) {
// PASTE THE NEW CODE HERE
if (index > 249) {
index = 599 - index
pixelCount = 150
} else {
pixelCount = 250
}
pct = index / pixelCount // Percent this pixel is into the overall strip
h = wave(wave(wave(t1 + pct)) - pct)
w1 = wave(t1 + pct)
w2 = wave(t2 - pct * 10)
v = w1 - w2
hsv(h, 1, v)
}
This will work for many of the 1D patterns. If you find some that still don’t look right, let us know which one looks off to you! Some that use pixelCount in other parts of the pattern may need a more specific fix.