Physics Simulation
Real-time particle/cloth/soft-body simulation in generative art rests on numerical integration such as Verlet integration (Loup Verlet, 1967) and later game-physics practice. A broad technique window rather than a single first.
community / folk Name — A descriptive category label, not a coined or eponymous name; no single coiner of the term is attested.
In one line Using a physics simulation — rigid bodies, soft bodies/Verlet, collisions or fluids — as the primary engine that drives the artwork's form and motion.
The code
The actual sketch behind the demo above — sandboxed and reproducible. This is the whole thing.
physics-sim/index.html
const SEED = Math.floor(Math.random()*1e9);
// Rigid-disc physics: gravity + wall bounce + pairwise elastic collisions.
// Discs settle and pack at the bottom of the canvas.
let discs = [], S;
function setup() {
randomSeed(SEED);
S = Math.min(windowWidth, windowHeight);
createCanvas(S, S);
colorMode(HSB, 360, 100, 100);
const baseHue = random(360);
const n = 60;
for (let i = 0; i < n; i++) {
const r = random(S*0.02, S*0.05);
discs.push({ x: random(r, S-r), y: random(r, S*0.4), vx: random(-2,2), vy: 0, r, m: r*r,
hue: (baseHue + random(-40, 40) + 360) % 360 });
}
noStroke();
}
function draw() {
background(40, 8, 92);
const g = S * 0.0009;
for (const d of discs) { d.vy += g; d.x += d.vx; d.y += d.vy; }
// walls
for (const d of discs) {
if (d.x < d.r) { d.x = d.r; d.vx *= -0.7; }
if (d.x > S-d.r) { d.x = S-d.r; d.vx *= -0.7; }
if (d.y > S-d.r) { d.y = S-d.r; d.vy *= -0.45; d.vx *= 0.92; }
}
// pairwise collisions (elastic, equal-ish)
for (let i = 0; i < discs.length; i++)
for (let j = i+1; j < discs.length; j++) {
const a = discs[i], b = discs[j];
let dx = b.x-a.x, dy = b.y-a.y;
let dist = Math.hypot(dx, dy) || 1e-4;
const overlap = a.r + b.r - dist;
if (overlap > 0) {
const nx = dx/dist, ny = dy/dist;
const push = overlap/2;
a.x -= nx*push; a.y -= ny*push; b.x += nx*push; b.y += ny*push;
const rvx = b.vx-a.vx, rvy = b.vy-a.vy;
const vn = rvx*nx + rvy*ny;
if (vn < 0) {
const imp = -1.6*vn/(1/a.m + 1/b.m);
a.vx -= imp/a.m*nx; a.vy -= imp/a.m*ny;
b.vx += imp/b.m*nx; b.vy += imp/b.m*ny;
}
}
}
for (const d of discs) { fill(d.hue, 60, 90); circle(d.x, d.y, d.r*2); }
}How it works
Step the world forward by a small time increment each frame: 1. Apply forces: gravity, drag, springs, attractors, user/field input — sum them per body into acceleration (a = F/m). 2. Integrate: advance velocity and position (semi-implicit Euler, or Verlet for stability and easy constraints). 3. Detect and resolve collisions/constraints: find overlaps (often via a broad-phase spatial grid), then push bodies apart and adjust velocities (impulse or position-based correction), iterating for stiff stacks. Sub-stepping and constraint iterations trade speed for stability. Art pieces let the emergent dynamics — piling, draping, flocking, splashing — produce the composition, sometimes freezing a moment as the final still.
Parameters
gravity: number — Constant acceleration applied to the bodies.restitution: number — Bounciness; the velocity retained after a collision.friction: number — Tangential resistance at contacts.timestep: number — Integration step of the solver.
Lineage
Frequently combined with
- Fragment Shader (GLSL) · 3 works
- Particle System · 2 works
- Audio-Reactive · 2 works
- Perlin / Simplex Noise · 2 works
- Marching Squares / Contours · 1 work
- HSL / Hue Cycle · 1 work
- Bezier / Catmull-Rom Splines · 1 work
- Flow Field / Vector Field · 1 work
- Instanced Geometry · 1 work
- Raymarching with SDFs · 1 work
- Glitch / Datamosh · 1 work
- Polygon Mosaic · 1 work
Works using this algorithm (12)
Last updated 2026-07-16