forever components

Particles & Physics

Bouncing Balls

7–14 glossy pastel balls bounce off walls and collide with elastic physics; cursor repels balls within a 70px radius.

canvasmedium complexitymoderate motionpointer

Open on the canvas to copy the code → Free account · 3 copies a day · membership goes unlimited

Live demo — the real component, running in a sandbox. One self-contained HTML file, zero dependencies. Open it on the canvas →
Worth keeping? Votes steer what gets built next — sign in to cast one, free to read

When to use it

Ambient physics backgrounds, playful landing pages, or demos showcasing interactive particle systems.

When not to

Content-heavy layouts where constant motion distracts from reading; low-end devices sensitive to per-frame O(n²) collision checks.

Working with an AI agent

Every component ships agent-ready metadata. An example instruction for this one:

Change the palette to warm sunset tones by replacing the pal array with ['#fb923c','#f472b6','#facc15','#f87171','#e879f9','#fbbf24'], and increase max ball count from 14 to 20 in the init() function. Theme: dark tokens live in :root, the light variant in :root[data-theme="light"]; ?theme=light or a {type:'forever:theme'} postMessage switches at runtime.

Safe to edit

  • ball count range (7–14, from W*H/9000 formula)
  • color palette (pal array)
  • cursor repel radius (70) and strength (0.6)
  • max speed cap (5)
  • ball radius range (7 + random * 18)
  • theme tokens (:root dark defaults + [data-theme=light] overrides)

Keep intact

  • DPR-aware canvas sizing and setTransform
  • visibilitychange pause/play guard
  • elastic collision momentum transfer math (p=2*(dvx*nx+dvy*ny)/(a.m+c.m))
  • theme hook (?theme= bootstrap + forever:theme message listener + theme tokens)

Known limitations

  • O(n²) collision detection — scales poorly beyond ~20 balls
  • No reduced-motion fallback beyond skipping the animation loop (draws one static frame)
  • Background color hardcoded in CSS (#0a1418)

physicsballscanvascollisionelasticparticlesbouncing

More Particles & Physics components

  • Gravity Dot RainMulticolored dots fall under gravity with motion trails, bounce off the floor, and scatter away from the cursor on a dark navy canvas.
  • Firework BurstColorful glowing sparks burst radially, fall under gravity, and fade against a dark sky. Auto-launches bursts; click anywhere to add more.
  • Confetti CannonColored rectangles fire from bottom corners in auto-cycling bursts, tumbling with gravity and flip animation. Click anywhere to trigger a cursor burst.
  • Spring ChainA 16-node spring chain whips and follows the cursor in a lime-to-gold gradient; drifts in a figure-eight pattern when idle.
  • Cloth Wave GridAn 11x11 wireframe grid ripples like cloth via sine/cosine waves in cyan-to-violet hues; mesh nodes bulge away from the cursor on hover.
  • Metaball Fluid7 hot-pink blobs drift and merge via a high-contrast canvas threshold; cursor adds an attracting blob that pulls them toward the pointer.