FireworksXY Just in time for the fireworks season,

Just in time for the fireworks season, here’s a (slightly) revised version of the Fireworks simulation I wrote a couple of years ago. This revised sketch Fireworks sketch should scale to different XY matrix sizes more easily.
The code is here: (and is still not terribly-well commented as these things go, but it’s a good starting point). It should be relatively portable; let us know what you get it running on … maybe post a video!
Enjoy, and have a happy, exciting, and safe (safety third!) 4th of July weekend!

Love it , I can 't stop staring at my matrix lol , great coding Mark.

Thanks for sharing! I can’t wait to try it on my 32x32 matrix! I hope to try it out tonight and post video.

Not sure if I’d mentioned this in the past, but the ‘Fireworks Simulator’ on STEAM at could also provide some inspiration.

Just what I looking for, thanks @Mark_Kriegsman

Most of this code is two years old; I feel I could do better if I started from scratch, but it makes me happy to share this around even as is. There are newer and fancier simulations (thanks for the specific links!) and I encourage everyone to experiment, and share their results!


If you have a matrix with serpentine layout, replace method XY with this one (same author):

CRGB& XY( byte x, byte y) {
uint16_t i;


if( x > PIXEL_WIDTH || y > PIXEL_HEIGHT) {
return overrun;

if( kMatrixSerpentineLayout == false) {
i = (y * PIXEL_WIDTH) + x;

if( kMatrixSerpentineLayout == true) {
if( y & 0x01) {
// Odd rows run backwards
uint8_t reverseX = (PIXEL_WIDTH - 1) - x;
i = (y * PIXEL_WIDTH) + reverseX;
} else {
// Even rows run forwards
i = (y * PIXEL_WIDTH) + x;

return leds[i];

Thanks @Thomas_Runge
The code not run on my 16x16 matrix until I change the WIDTH to 15

I wonder how well it would work on a 16x5 matrix :slight_smile:

Try removing the initial pixel offset subtraction. I’m not sure, what that is for. But it was in the original code.

Garett: there is one easy way to find out! :wink:

Garrett: THAT a great idea! Hrm. I’d want to rethink it a bit but I suspect the answer is YES.

Also, I may have to tweak the code to handle more than 256 pixels. I have this habit of using the narrowest data types I need (ESPECIALLY on AVR), which is often just a byte. Just a habit born of long hours of optimizing code, I guess. Then I go to scale up, and oops-- need to upgrade to uint16_t!

I just adapted it for a 32x32 SmartMatrix:

It needs some more tweaking. It’s a bit ‘jerky’, and some shells go off the top of the screen and wrap to the bottom. But it still looks great! Thanks again!

P.S. I only found one byte that I had to change to a uint16_t. :slight_smile:

@Jason_Coon : maybe take a look at the groundlaunch method and reduce the “25” down to 20 or 15 and see if that helps with the escaped shells.

And I see that “dark blue sky twinkle” uint16_t there- I just updated the original. Thanks!

Looking over this two-year-old code, I bet if I wrote it from scratch today it’d be half as long. You know that feeling? And in open-source software, one tends to be a little more self-conscious than usual about that. But for now, I’ll just say Thanks, me-from-two-years-ago. It’s not bad.

@Thomas_Runge It now works on my 8x8 (homemade) Serpentine layout if I replace:



if( x >= PIXEL_WIDTH || y >= PIXEL_HEIGHT)

Thanks for this!

@Thomas_Runge when I try and compile it says kMatrixSerpentineLayout was not declared? do I need to #DEFINE it? and if so how would I go about doing that? I have a 8x39 vertical zigzag matrix I would like to try this on, But when I try to edit the variables to make it work everything turns out a little funny?

@Aren_Hibbing Sure, just #define if you have serpentine layout or not. Reference: