Physics-Based Fireworks

Physics-Based Fireworks

A canvas-based fireworks simulation with launching shells, multi-color particle bursts, gravity trails, and radial glow. Click anywhere to launch a shell. Auto-launches when idle.

Helpful?

Was the prompts helpfull?

Case trace

2 creative leaps

Step 1 — Physics engine & particle systemClaudeSonnet 4.6

Build a physics-based fireworks system on HTML5 Canvas. Shells launch from the bottom with upward velocity, explode into 60–80 particles with randomized burst angles and speeds. Add gravity (0.08 per frame) pulling particles down. Each particle has a tail — store the last 8 positions and draw them as fading line segments. Fade opacity out as lifetime decreases. Loop with requestAnimationFrame. Click to launch at cursor X, auto-launch every 1.8s if idle. Use a dark semi-transparent clear (rgba 0,0,0,0.15) each frame for motion blur trails. 6 palette colors: gold, crimson, cyan, lime, violet, coral.

The semi-transparent fill trick (rgba 0,0,0,0.15 per frame) creates motion blur without storing frame buffers — particles naturally ghost as they move. Tail length of 8 at 60fps gives ~133ms of trail per particle.

tsx
const PALETTE = ['#FFD700','#FF4455','#00E5FF','#7CFF50','#BF7AFF','#FF6B35'];
const GRAVITY = 0.08;

class Particle {
  constructor(x, y, vx, vy, color) {
    this.x = x; this.y = y;
    this.vx = vx; this.vy = vy;
    this.color = color;
    this.life = 1;
    this.tail = [];
  }
  update() {
    this.tail.push({ x: this.x, y: this.y });
    if (this.tail.length > 8) this.tail.shift();
    this.vy += GRAVITY;
    this.vx *= 0.98;
    this.x += this.vx;
    this.y += this.vy;
    this.life -= 0.014;
  }
}
Step 2 — Shell launch arc, glow & burst ringClaudeSonnet 4.6

Enhance the fireworks with: (1) Shell object — a bright dot that travels upward from (x, canvasH) with vy = -(12 to 16), slightly wobbly vx drift. When shell.vy >= 0 it explodes: emit 60 particles in full 360° spread, burst speed 2–6. (2) Radial glow on explosion — draw a radialGradient circle at burst origin (radius 80px, color-matched, alpha 0.6→0) before particles. (3) Outer ring expansion — large circle stroke that starts at r=5, expands to 60px, fades out over 20 frames. (4) Shockwave: 3 concentric rings at different speeds. Cap concurrent shells at 6 for performance.

Published 6 mo ago

Category

Code

Tools used

Claude

Details

Tech stack

HTMLCSSJS

Tags

canvasanimation

More from Jimmy SIam

Dissolving Memory — Ink & Water Portrait
100% helpful

Dissolving Memory — Ink & Water Portrait

abstract cinematic portrait, fragility of human memory, human face partially dissolving into water, liquid ink swirling through crystal-clea…

Adobe Fireflyillustration
Koi Pond — Canvas Simulation

Koi Pond — Canvas Simulation

Build a koi pond simulation using an HTML5 canvas. Fish should flock using boids rules (separation, cohesion, alignment) with wander behavio…

ClaudeHTMLCSS
Realistic Canine Motion Study

Realistic Canine Motion Study

Ultra-detailed low-poly origami corgi portrait, centered composition, sitting pose, crafted entirely from folded paper polygons and geometri…

GeminiBing Image Creator

View similar

Falling Sand Sandbox

Falling Sand Sandbox

write a falling sand simulation in plain javascript on a canvas. use one flat Uint8Array for a 320x180 grid, scan it bottom-up each tick, an…

Grok
Double-Slit Ripple Tank

Double-Slit Ripple Tank

Build a 2D ripple tank as a single HTML file at 1280x720 with a dark deep-slate and teal look, vanilla JS and canvas only, no libraries. Sim…

Grok
Three-Pendulum Ink Plotter

Three-Pendulum Ink Plotter

Build a harmonograph ink plotter as a single static HTML page, 1280x720, no libraries. Two damped pendulums drive one pen: x = ax*sin(2*PI*f…

Grok
Voronoi Stained Glass

Voronoi Stained Glass

Write the core of a voronoi stained glass generator in plain JavaScript, no libraries. One function, voronoi(seeds, mask, w, h, label, edge)…

Grok
Ebru Marbling Tray

Ebru Marbling Tray

Build a paper marbling (ebru) tray as a single html file with a 1280x800 canvas and no libraries. Store every ink drop as a polygon and appl…

Grok
Split-Flap Station Board

Split-Flap Station Board

Build a static solari-style railway departures board as a single html file at 1280x800. Dark brushed-metal housing with corner rivets, a CEN…

Grok