Visualizations
086 / 500

086 · Math

Lorenz Attractor

Hundreds of trajectories swirl around the famous butterfly.

The Lorenz system is three simple equations that never settle into a repeating loop. Hundreds of particles start close together and are integrated in 3D, rotated, and projected onto the screen with fading tails. They quickly spread across both wings of the attractor, showing order emerging from chaos.

Try it. Drag to orbit the camera. Click to release a new cloud of particles.

  • Numerical integration
  • 3D projection
  • Strange attractors

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 an animated Lorenz attractor 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. Use a near-black navy background.
- The Lorenz system is dx/dt = 10 (y - x), dy/dt = x (28 - z) - y, dz/dt = x y - (8/3) z.
- Create 300 particles that all start within 1 unit of the point (0, 0.5, 12). Every frame, advance each one by about 0.012 time units using a few small steps.
- Give each particle a tail: a ring buffer of its last 40 positions stored in a Float32Array.
- Slowly rotate everything around the vertical z axis, tilt it a little, and project with a perspective divide, centered on z = 25.
- Draw each tail as line segments that get more transparent toward the end.

Once that works, make it beautiful:
- Color by wing (blue when x < 0, pink when x > 0), brighten faster segments, and draw with globalCompositeOperation = "lighter" so dense regions glow.
- Batch the segments into one path per color and opacity level so thousands of lines stay smooth at 60 fps.
- Let me drag to orbit the camera with inertia, and click to release a new tight cloud of particles where I clicked.

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 sliders for sigma, rho and beta, other attractors like Rossler or Aizawa, or a plot showing how fast two nearby particles separate.
PreviousWind TunnelA lattice Boltzmann wind tunnel: draw any shape and watch it shed vortices. NextChirpTwo black holes spiral together and ring spacetime, from post-Newtonian formulas.

Related visualizations

  • IFS EditorFractals Sculpt fractals by dragging affine parallelograms while the chaos game redraws them.
  • Road to ChaosMath The logistic map's bifurcations, Mandelbrot bulbs and a cobweb, linked in one picture.
  • Three-Body BalletPhysics Twenty-two periodic three-body orbits, inked like calligraphy until a nudge breaks them.
  • Lagrange LandscapePhysics The restricted three-body problem as a plaster relief, Trojans looping on its summits.
  • Echo State OracleMachine learning A never-trained random reservoir forecasts chaos on a green phosphor oscilloscope.
  • Lyapunov FractalFractals Type a string of A and B and the logistic map grows gold and teal enamel jewelry.
  • SLE CurvesMath Random fractal curves grown tip first from Loewner's equation, kappa by kappa.
  • Flow FieldGenerative art Thousands of particles ride an evolving noise field into silky trails.
  • Space-Filling CurvesMath Hilbert, Peano, Gosper and friends fold smoothly from one order to the next.

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

← More from Emergent Mind Labs