Strange Attractor

First appeared 1963 · Edward Lorenz — Edward Lorenz (1963); Clifford/De Jong attractors later popularized in art. · timeline ↗

third-party / eponym Name (1971) — Two-track split: the phenomenon dates to Lorenz (1963), but the NAME "strange attractor" was coined by David Ruelle and Floris Takens in "On the Nature of Turbulence" (1971) — the namers are not the discoverer.

In one line A chaotic dynamical system (Lorenz, Clifford, De Jong, Pickover…) whose orbit is drawn out by iterating a few simple equations: the trajectory never repeats yet stays bound to an intricate fractal set.

Strange Attractor · 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.

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

// Clifford attractor:  x' = sin(a·y) + c·cos(a·x), y' = sin(b·x) + d·cos(b·y)
// Random (a,b,c,d) often degenerate — use a curated list of known-attractive
// parameter sets (the visual is always non-trivial).
const PARAMS = [
  [-1.4,  1.6,  1.0,  0.7],
  [-1.7,  1.3, -0.1, -1.21],
  [ 1.5, -1.8,  1.6,  0.9],
  [-1.8, -2.0, -0.5, -0.9],
  [-1.7,  1.8, -1.9, -0.4],
  [ 1.6, -0.6, -1.2,  1.6],
  [-2.0, -2.0, -1.2,  2.0],
  [-1.24, -1.25, -1.81, -1.91],
  [ 1.7,  1.7,  0.6,  1.2],
  [-1.7,  1.8, -0.9, -0.4],
];

function setup() {
  randomSeed(SEED);
  const s = Math.min(windowWidth, windowHeight);
  createCanvas(s, s);
  background('#0a0a0a');
  noStroke();

  const [A, B, C, D] = PARAMS[Math.floor(random(PARAMS.length))];

  // Iterate to compute bounds (warm-up + bounding box).
  let x = 0.1, y = 0.1;
  for (let i = 0; i < 1000; i++) {
    const nx = Math.sin(A * y) + C * Math.cos(A * x);
    const ny = Math.sin(B * x) + D * Math.cos(B * y);
    x = nx; y = ny;
  }
  let xmin = Infinity, xmax = -Infinity, ymin = Infinity, ymax = -Infinity;
  for (let i = 0; i < 20000; i++) {
    const nx = Math.sin(A * y) + C * Math.cos(A * x);
    const ny = Math.sin(B * x) + D * Math.cos(B * y);
    x = nx; y = ny;
    if (x < xmin) xmin = x;
    if (x > xmax) xmax = x;
    if (y < ymin) ymin = y;
    if (y > ymax) ymax = y;
  }
  const xspan = xmax - xmin || 1;
  const yspan = ymax - ymin || 1;
  const span = Math.max(xspan, yspan) * 1.05;
  const offsetX = (xmin + xmax) / 2;
  const offsetY = (ymin + ymax) / 2;

  // Density buffer keyed by canvas-space pixel.
  const N = 280000;
  const density = new Float32Array(width * height);
  let maxD = 0;
  x = 0.1; y = 0.1;
  for (let i = 0; i < 1000; i++) {
    const nx = Math.sin(A * y) + C * Math.cos(A * x);
    const ny = Math.sin(B * x) + D * Math.cos(B * y);
    x = nx; y = ny;
  }
  for (let i = 0; i < N; i++) {
    const nx = Math.sin(A * y) + C * Math.cos(A * x);
    const ny = Math.sin(B * x) + D * Math.cos(B * y);
    x = nx; y = ny;
    const px = Math.floor(((x - offsetX) / span + 0.5) * width);
    const py = Math.floor(((y - offsetY) / span + 0.5) * height);
    if (px >= 0 && py >= 0 && px < width && py < height) {
      const idx = py * width + px;
      density[idx] += 1;
      if (density[idx] > maxD) maxD = density[idx];
    }
  }

  pixelDensity(1);
  loadPixels();
  const logMax = Math.log(1 + maxD);
  for (let i = 0; i < density.length; i++) {
    if (density[i] === 0) continue;
    const t = Math.log(1 + density[i]) / logMax;
    // magma-ish ramp: black → purple → red → orange → yellow
    const r = Math.round(255 * Math.min(1, t * 1.6 - 0.1));
    const g = Math.round(255 * Math.max(0, t * t * 1.4 - 0.3));
    const bl = Math.round(255 * Math.max(0, 0.5 * t - Math.max(0, t - 0.5)));
    const idx = i * 4;
    pixels[idx]     = r;
    pixels[idx + 1] = g;
    pixels[idx + 2] = bl;
    pixels[idx + 3] = 255;
  }
  updatePixels();
}

Open the demo source ↗

How it works

Take a point and a small set of update equations with fixed parameters — e.g. the De Jong map xₙ₊₁ = sin(a·yₙ) − cos(b·xₙ), yₙ₊₁ = sin(c·xₙ) − cos(d·yₙ). Then: 1. Start from a seed point. 2. Apply the equations repeatedly to get the next point, for millions of steps. 3. Plot (or accumulate density at) each point; discard the first hundreds of iterations so the orbit settles onto the attractor. The system is deterministic but sensitive to initial conditions (chaos), so the orbit fills an elaborate, self-similar shape. Density accumulation + tone-mapping reveals fine filament structure; the parameters a,b,c,d are the "genome".

Parameters

Lineage

Related
Physics Simulation

Frequently combined with

Works using this algorithm (6)

Attraction
jos-vromans
Augmented Sequence
toiminto
Edifice
ben-kovach
Gravity 16
jimmy-herdberg
Hashtractors
darien-brito
Human Unreadable
operator

Last updated 2026-07-16