# How to reverse direction of firework rocket sparks

Im trying to figure out how to reverse the direction of the rockets and sparks on the strip.

I imagine its easy if you know, but i cant figure it out.

any help would be appreciated.

Thanks,
P-Dog

Hi and welcome!
The easiest way to reverse the direction of this pattern is to virtually reverse the direction of the LED strip.

To do this, just add the a line like the following as the first line of the render() function when you want to go the other way:
`index = -1+pixelCount-index`

How this works:
In render(), index is the number of the current pixel. Normally, this runs from 0 to pixelCount-1.
We â€śflip the stripâ€ť by subtracting the â€śrealâ€ť index from pixelCount so that it runs from pixelCount-1 to start. Once weâ€™ve done this reversal, we donâ€™t have to touch the rest of the pattern math at all.

Hereâ€™s a version of the pattern equipped with a slider that lets you control direction from the UI:

``````var dir = 0

export function beforeRender(delta) {
t1 = time(.05)
t2 = time(0.0001) * 0.2
}

export function sliderDirection(d) {
dir = d >= 0.5;
}

export function render(index) {
if (dir) index = -1+pixelCount-index
v = wave(t1 + index/pixelCount)
v2 = wave(t1 + (index+10)/pixelCount)
s = (v2 < 0.9995)
v = (v > .95 && random(1) > .95) * v
h = random(1)
h = (s ? h : (index/20)%.2)
hsv(h, 1-s, (1-s) + v )
}
``````
2 Likes

Appreciate you taking the time to answer.

I will try it out.

Thanks Again,

P-Dog

Switch to the toggle controls (introduced in v3.24 and v2.29) and you get a nice switch!

``````export function toggleDirection(d) {
dir = d
}
``````

It all comes down to the magic (key)word used

1 Like

That did work great,
Thank you so much for your time!

1 Like