A colony digs its nest grain by grain behind glass, with no plan but local rules.
The farm is a grid of sand grains with layered strata, and every grain keeps its own color. Diggers walk only where they have footing, lean downhill, and steer toward fresh digging pheromone; they pick up the grain ahead with a probability set by that pheromone, by moisture, and by how much open space surrounds it, so tunnel tips advance while walls hold and the nest branches like roots, with small chambers where resting ants have marked a spot. Loaded ants climb a breadth-first distance field to the surface and drop their grain where loose sand already lies, so spoil heaps of mixed strata build up by stigmergy and slide like falling sand. Foragers run food back along the ground, laying a trail pheromone (the violet haze) that recruits others, and store the seeds deep in the nest, while water seeps through the sand and darkens it. A rival red colony moves in across the farm early on, so two nests race each other down through the strata.
Try it. Pick a tool below: Food drops a pile of seeds where you click, Water pours where you drag, and Red colony refounds the rival colony wherever you click on the surface. Speed cycles 1x, 4x and 16x. Keys: F for food, W for a rain shower, C to refound the rival, 1 to 3 for speed, R to start over.
Paste this into Claude Code, Codex or any coding agent to get a simple version running, then take it wherever you like.
Build a side-view ant farm with JavaScript and the HTML canvas element, where ants dig tunnels grain by grain using only local rules. 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 full-window canvas. Use a grid of 4-pixel cells: the top quarter air, the rest sand in a few colored bands with per-grain noise, drawn through an ImageData buffer scaled up with smoothing off.
- Start with a short shaft at the entrance and add 60 ants. An ant can only stand in an air cell that touches sand or the edge of the farm, so they walk on surfaces and through tunnels.
- A digging ant keeps its heading, leans slightly downward, and when the cell in front of it is sand it picks the grain up with a small probability. Make that probability much higher where other ants have dug recently: keep a digging pheromone grid that grows where a grain is removed and slowly evaporates.
- To keep tunnels narrow, rarely dig a grain that already has lots of open space around it in a 5x5 window. Tips get dug, walls hold.
- A loaded ant finds its way out by following a breadth-first distance field from the surface through the open cells, then walks along the ground and drops the grain as loose sand that falls like a falling-sand simulation.
Once that works, make it beautiful:
- Draw each ant as three little ellipses with six legs that swing in a tripod gait, carrying a grain in its jaws in the color it was dug from.
- Shade tunnel ceilings darker and floors lighter, and add a wooden frame and a faint glass reflection.
- Add foragers that find seeds on the surface and lay a trail pheromone on the way home that others follow.
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 water that soaks into the sand, a second rival colony, or chambers that open where resting ants gather.