Particles & Physics
N-Body Waltz
Five glowing gravitational bodies orbit and sling each other in deep space, trailing colored comet tails; pointer perturbs the dance, click reseeds.
canvasheavy complexityintense motionpointer
Open on the canvas to copy the code → Free account · 3 copies a day · membership goes unlimited
Worth keeping?
Votes steer what gets built next — sign in to cast one, free to read
When to use it
Dark-mode hero backgrounds, space/science themes, generative art displays where constant motion is welcome.
When not to
Low-end devices (O(N²) physics loop per frame with 3 substeps). Any context requiring legible text overlays or light backgrounds.
Working with an AI agent
Every component ships agent-ready metadata. An example instruction for this one:
Increase body count to 7 by changing N=5 to N=7 and add two palette entries to PAL, then slow trails by reducing TLEN from 46 to 30. 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
- body count (N=5)
- gravitational constant (G=1400)
- trail length (TLEN=46)
- color palette (PAL array)
- pointer repulsion strength (f=2600/d2)
- substep count (sub=3)
- theme tokens (:root dark defaults + [data-theme=light] overrides)
Keep intact
- DPR-aware canvas sizing and ctx.setTransform
- visibilitychange pause/start guard
- reduced-motion static fallback (draw after 140 steps)
- IIFE wrapper
- theme hook (?theme= bootstrap + forever:theme message listener + theme tokens)
Known limitations
- O(N²) gravity loop runs 3 substeps per frame — heavy on low-end CPUs as N grows
- Background color hardcoded (#05060f) — must edit CSS to change from deep navy
- Soft recentering and leash may cause subtle energy drift in long runs
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.
- Bouncing Balls7–14 glossy pastel balls bounce off walls and collide with elastic physics; cursor repels balls within a 70px radius.
- 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.