Visualizations
483 / 500

483 · Nature

Wandering Dunes

Crescent dunes march across a desert, built by a three-rule sand slab model.

The desert floor is a grid of sand columns made of stacked slabs. In Werner's model the wind lifts a random exposed slab and hops it downwind until it sticks, more readily on sand than on bare ground and always in the wind shadow behind a dune, and any step steeper than the angle of repose avalanches. From those rules alone, mounds blown in from upwind become crescent barchans with horns pointing downwind, and small, fast dunes catch big, slow ones, merge and calve. The grid stays aligned with the wind and is resampled whenever the wind turns, and the heights are lit by a low sun that casts long shadows, with ripples across the windward slopes.

Try it. Click to drop a pile of sand, or hold and drag to pour. Drag the compass to turn the wind. Pick Barchan, Linear, Star or Transverse to change the sand supply and wind regime (keys 1 to 4, or Space to step through them); the arrow keys turn the wind and change the supply, and R reseeds the desert.

  • Werner slab model
  • Wind shadow sweeps
  • Low-sun hillshading

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 desert dune simulation with JavaScript and the HTML canvas element, using Werner's slab model of wind-blown sand. 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 and stays sharp on high-DPI screens. Keep a 200 by 120 grid of integer heights (stacks of sand "slabs") in an Int16Array, with the wind blowing along +x.
- Seed the grid with a few cone-shaped piles of a few thousand slabs each on bare ground.
- One event: pick a random cell. If it has sand and is not in a wind shadow, remove one slab and hop it 3 cells downwind. Where it lands, it sticks with probability 0.6 on sand, 0.4 on bare ground, or always if that cell is in a shadow; otherwise it hops again. A cell is in shadow if some cell upwind is taller by more than 0.8 slabs per cell of distance (a 15 degree line).
- After every pickup and drop, avalanche: while a cell is more than 2 slabs higher than a neighbour, move a slab down to it.
- Run one event per cell each frame and draw the heights in grayscale. Sand blows off the right edge; add new piles at the left.

Once that works, make it beautiful:
- Light the slopes with a low sun: warm orange sand on a darker brown floor.
- Cast long shadows by sweeping across each row and tracking the highest sun ray.
- Blur the heights slightly before shading, and add faint ripples across the wind.
- Let a click drop a new pile and watch it become a crescent.

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 turning the wind (by rotating the grid), alternating two wind directions to grow linear dunes, or measuring how dune speed depends on size.
PreviousWater EconomyA glass-and-brass hydraulic computer where water is money and valves are policy. NextCircle PackingThurston's discrete Riemann map: a live circle packing warps a picture into your blob.

Related visualizations

  • Lens FlareType and image Drag the sun over the dunes; ghosts traced through a real lens follow it.
  • Seed DispersalPhysics Samaras autorotate, dandelion seeds parachute and leaves flutter across a gusty meadow.
  • Chladni PlateSound Sand dances into Chladni figures on a brass plate whose modes come from the Ritz method.
  • ErosionNature Raindrops carve rivers and valleys into a mountain range.
  • Fractal TreeNature A recursive tree that grows, blossoms and sways in the wind.
  • Volumetric CloudsNature Raymarched cumulus with silver linings, light shafts and drifting shadows.
  • WildfireSimulation A fire runs uphill and downwind across a topographic incident map, trailing smoke.
  • Falling SandSimulation Sand, water, fire, lava and plants that all react with each other.
  • Mountain Wave CloudsSimulation Wind over a range rings into lee waves, and saucer clouds stack at the crests.

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

← More from Emergent Mind Labs