Spring-Mass / Verlet

First appeared 1967 — The numerical core — Verlet integration — originates in Loup Verlet's 1967 molecular-dynamics work on classical fluids (the scheme had earlier precedents and was rediscovered several times). Its use for interactive cloth, rope and soft-body line work was popularized by Thomas Jakobsen's 2001 GDC talk "Advanced Character Physics." The year marks the integration method, not a single artwork. · timeline ↗

community / folk Name — A descriptive category label, not a coined or eponymous name; no single coiner of the term is attested.

In one line A physics simulation of point masses connected by springs (often integrated with Verlet). Used for cloth, rope, soft bodies and constraint-driven dynamic line work.

Spring-Mass / Verlet · Open in new tab ↗ · Motion begins only when you press Run.

The code

The actual sketch behind the demo above — sandboxed and reproducible. This is the whole thing.

spring-mass/index.html
const SEED = Math.floor(Math.random()*1e9);

// Verlet cloth: a grid of point masses linked by distance constraints,
// pinned along the top, settling under gravity. Constraints relaxed
// iteratively (Jakobsen 2001).
let pts = [], cons = [], COLS, ROWS, S;

function setup() {
  randomSeed(SEED);
  S = Math.min(windowWidth, windowHeight);
  createCanvas(S, S);
  COLS = 18; ROWS = 18;
  const gap = S * 0.045, ox = (S - gap*(COLS-1))/2, oy = S*0.1;
  for (let j = 0; j < ROWS; j++)
    for (let i = 0; i < COLS; i++) {
      const x = ox + i*gap, y = oy + j*gap;
      pts.push({ x, y, px: x, py: y, pin: j === 0 && i % 3 === 0 });
    }
  const idx = (i,j) => j*COLS+i;
  for (let j = 0; j < ROWS; j++)
    for (let i = 0; i < COLS; i++) {
      if (i < COLS-1) cons.push([idx(i,j), idx(i+1,j), gap]);
      if (j < ROWS-1) cons.push([idx(i,j), idx(i,j+1), gap]);
    }
  stroke(120, 200, 255); strokeWeight(S*0.0015); noFill();
}

function draw() {
  background(10, 12, 18);
  // integrate
  const g = S * 0.0006;
  for (const p of pts) {
    if (p.pin) continue;
    const vx = (p.x - p.px) * 0.99, vy = (p.y - p.py) * 0.99;
    p.px = p.x; p.py = p.y;
    p.x += vx; p.y += vy + g;
  }
  // relax constraints
  for (let k = 0; k < 8; k++) {
    for (const [a, b, len] of cons) {
      const pa = pts[a], pb = pts[b];
      const dx = pb.x - pa.x, dy = pb.y - pa.y;
      const d = Math.hypot(dx, dy) || 1e-4;
      const diff = (len - d) / d * 0.5;
      const ox = dx*diff, oy = dy*diff;
      if (!pa.pin) { pa.x -= ox; pa.y -= oy; }
      if (!pb.pin) { pb.x += ox; pb.y += oy; }
    }
  }
  // draw mesh
  for (const [a, b] of cons) line(pts[a].x, pts[a].y, pts[b].x, pts[b].y);
}

Open the demo source ↗

How it works

Model the object as particles (masses) joined by springs with a rest length. Each step: 1. Force/spring solve: for every spring, compute the restoring force from how far it is stretched or compressed (Hooke's law, F = −k·Δx), plus damping; add external forces like gravity and wind to each mass. 2. Integrate: advance each particle. Verlet integration is popular — x_next = x + (x − x_prev) + a·dt² — because it is stable and stores velocity implicitly in the previous position. 3. Constraint relaxation: instead of stiff springs, many cloth solvers just push particle pairs back toward rest length a few iterations per frame (position-based dynamics), which is robust at large steps. Pinning some particles and tuning stiffness/damping yields cloth, hanging ropes and wobbling structures.

Parameters

Lineage

Related
Physics Simulation, Particle System

Frequently combined with

Works using this algorithm (5)

Balance
kelly-milligan-x-amber-vittoria
Cytographia
golan-levin
Memories of Qilin
emily-xie
SKEUOMORPHS
itsgalo
Space Debris [warning]
whalestreet-x-pxlq

Last updated 2026-07-16