Every project / Art & Animation

šŸŽ† Fireworks

Click anywhere to launch a firework. Hundreds of glowing particles, a few lines of physics.

Fireworks running
Language
HTML, CSS & JavaScript
Level
Beginner
Category
Art & Animation
ā–¶ Try it & remix

What you'll learn

  • Particle systems
  • Gravity & friction
  • HSL colors
  • Trails with transparency
  • Mouse clicks

How it works

  • A click launches a rocket that eases toward where you clicked, then bursts into 90 sparks.
  • Each spark has its own speed and direction. Gravity pulls it down and friction slows it.
  • Every frame erases a little of the last picture (destination-out), which leaves glowing trails.
  • The 'lighter' blend mode adds overlapping sparks together, so busy spots glow brighter.

Knobs to turn

These settings are near the top of the code. Remix it, change one, and watch what happens. The preview updates as you type.

SettingStarts atFileWhat it does
SPARKS90fireworks.jssparks per explosion
GRAVITY0.06fireworks.jshow fast sparks fall
FRICTION0.985fireworks.js1 = sparks never slow down
AUTO_EVERY1500fireworks.jsms between automatic fireworks (0 = off)

Files

FileLines
index.html19the page: what shows up
fireworks.js86what it does

Challenges

Each one is a bit harder than the last. Teachers: these make good assignment instructions.

  1. Change how many sparks each firework makes.
  2. Set AUTO_EVERY to 200 for a finale, then make the finale stop after 10 seconds.
  3. Give each firework two colors instead of one.
  4. Make a firework that explodes into a heart or star shape.
  5. Add a crackle: sparks that split into smaller sparks when they fade.