Visualizations
115 / 500

115 · Physics

Tearable Cloth

A sheet of Verlet points and springs that sags, swings and rips.

The cloth is a grid of points joined by distance constraints. Each frame, Verlet integration moves every point by its own momentum plus gravity, then a few relaxation passes nudge each pair of points back toward their rest length. A constraint stretched too far snaps, so tears spread realistically. A gentle wind keeps it alive.

Try it. Drag to pull the cloth. Right-click and drag, or Shift-drag, to cut it. Press R to rehang it.

  • Verlet integration
  • Constraint relaxation
  • Breakable springs

View the source · one module, plus a small shared runtime for sizing, the animation loop and input

Build your own

Paste this into Claude Code, Codex or any coding agent to get a simple version running, then take it wherever you like.

Build a tearable cloth simulation with JavaScript and the HTML canvas element. Put everything in a single index.html file with no libraries or build step, so I can open it directly in a browser.

Start simple:
- Make a canvas that fills the window, stays sharp on high-DPI screens (scale by devicePixelRatio), and resizes with the window. Paint it a dark background.
- Create a grid of about 40 x 25 points spaced 12 pixels apart, hanging from the top of the screen. Pin every few points in the top row so they never move.
- Join each point to its right and lower neighbors with a distance constraint whose rest length is the grid spacing.
- Move the points with Verlet integration: a point's velocity is its current position minus its previous position, so each step store the old position, add that velocity plus gravity, and you're done. Use a fixed time step of 1/60 s.
- After moving, run 5 relaxation passes over every constraint, nudging both ends halfway toward the rest length (skip pinned points).
- If a constraint stretches past about 3 times its rest length, delete it. That is all tearing takes.
- Drag with the mouse to pull the points near the cursor along with it, and right-click drag to cut constraints near the cursor. Draw every constraint as a line.

Once that works, make it beautiful:
- Fill each grid cell as two triangles instead of drawing lines, and skip a triangle when one of its edges has torn.
- Shade each cell by how squashed it is compared with its rest area so folds look darker, and use a stripe pattern from the grid coordinates so the fabric reads like tartan.
- Add a gentle gusting wind with a little noise across the sheet, and press R to rehang it.

Explain the key ideas in short code comments. When you're done, tell me how to open it and suggest three directions I could take it next, such as wrapping a photo texture onto the cloth, adding diagonal constraints for stiffer fabric, or letting the cloth collide with a ball.
PreviousASCII RendererA rotating 3D scene drawn in characters chosen by shape, not just brightness. NextMandelbrot ZoomAn endless dive into the Mandelbrot set, 10^31 times deep.

Related visualizations

  • Climbing VineNature Sweet pea shoots circle, grab supports with tendrils and coil into springs.
  • Tensegrity3D Struts that never touch, floating in a web of cables, found by dynamic relaxation.
  • Drying MudSimulation Wet clay dries and cracks into a lakebed of curling plates, primaries first.
  • JellyPhysics Squishy soft bodies that wobble, bounce and squash into each other.
  • Kelp ForestPhysics Buoyant kelp sways in an ocean surge under god rays and live caustics.
  • Weaving LoomGenerative art A floor loom weaves shaded yarn cloth live from historical drafts you can edit.
  • Hanging Chain ArchesPhysics Hang chains and weights, then flip the sheet to turn them into stone arches.
  • Truss Bridge BuilderPhysics Draft a bridge on blueprint paper, then send a truck over as each beam shows its stress.
  • Aperture ProblemIllusions One grating, one true motion, three holes that each report a different direction.

Use ← and → to move between demos. While the canvas has focus, keys go to the demo instead.

← More from Emergent Mind Labs