Visualizations
295 / 500

295 · Generative art

Fireworks

Shells arc, burst and crackle with glowing, fading sparks.

Each shell is a particle launched with an initial velocity under gravity. At its peak it bursts into a hundred or more sparks with randomized speeds and air drag, in shapes like peonies, rings, willows and crossettes that split again in mid-air. Each spark is drawn as a short streak along its velocity with additive blending, so overlapping sparks glow, and the bursts light the sky and ripple in the water below.

Try it. Click anywhere to launch a shell toward that point. Hold to fire a volley.

  • Particle systems
  • Gravity and drag
  • Additive blending and velocity streaks

View the source · one module, plus a small shared runtime for sizing, the animation loop and input

Build your own

Paste this into Claude Code, Codex or any coding agent to get a simple version running, then take it wherever you like.

Build a fireworks show with JavaScript and the HTML canvas element. Put everything in a single index.html file with no libraries or build step, so I can open it directly in a browser.

Start simple:
- Make a canvas that fills the window, stays sharp on high-DPI screens (scale by devicePixelRatio), and resizes with the window. Paint it a dark night-sky gradient.
- A shell is a particle launched upward from the bottom with gravity pulling it down. Choose its starting speed so it peaks at a target height: vy = -sqrt(2 * gravity * height).
- When the shell's vertical speed reaches zero, replace it with about 150 sparks with random directions and speeds and a lifetime of 1 to 2 seconds.
- Each frame, apply gravity and a little air drag (multiply velocity by about 0.98), move the sparks, and fade them out as they age.
- Instead of clearing the canvas, fill it with the background color at about 20% opacity, so sparks leave short trails.
- Launch a new shell at a random spot every second or so, and launch one toward the mouse when I click.

Once that works, make it beautiful:
- Draw sparks with globalCompositeOperation = "lighter" so overlaps glow, and use a pre-rendered radial-gradient sprite for each color.
- Add different burst shapes: a peony (sparks in a sphere), a ring (same speed, evenly spaced angles), a willow (long-lived gold sparks with heavy drag), and a crossette (a few stars that split into four).
- Add a dark city skyline along the bottom and a brief glow in the sky at each burst.

Explain the key ideas in short code comments. When you're done, tell me how to open it and suggest three directions I could take it next, such as a mirrored reflection in water, shells that draw shapes like hearts or text, or a timed finale.
PreviousIndra's PearlsLimit sets of Kleinian groups, strung as glowing necklaces of nested circles and pearls. NextAntikythera MechanismThe 2,000-year-old Greek computer, every gear meshing, scrubbing across centuries.

Related visualizations

  • Flow FieldGenerative art Thousands of particles ride an evolving noise field into silky trails.
  • BonfireFluids A campfire whose flames are a fluid simulation colored by blackbody physics.
  • Seashell PatternsNature Meinhardt's lip chemistry paints tents, bands and dots onto a growing 3D shell.
  • Particle TypeType and image Words made of thousands of particles that scatter and regroup.
  • SPH WaterFluids Thousands of particles that slosh, splash and pour like a liquid.
  • Lava LampGenerative art Glowing blobs that merge and split like a lava lamp.
  • BreakoutGames The arcade classic, with sparks, screen shake and an autopilot.
  • Glenz VectorsRetro Nested glassy checkered polyhedra bounce on a glossy floor, then shatter and rebuild.
  • Op ArtGenerative art Riley and Vasarely style compositions that ripple, bulge and vibrate.

Use ← and → to move between demos. While the canvas has focus, keys go to the demo instead.

← More from Emergent Mind Labs