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.
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.