Skip to content
Adrien Hubert

Physarum, six thousand agents on a trail.

Each agent is a point with a heading. It looks three directions ahead, picks the brightest cell of pheromone, and steers toward it. It deposits a little pheromone of its own as it moves. The trail diffuses outward and fades. Run that loop with six thousand agents and the network of veins that forms looks a lot like the real Physarum polycephalum, a single-celled slime mold that solves shortest-path problems by growing.

30°
0.97

What you are seeing

The bright threads are pheromone, the strands the agents have painted onto a 360 by 360 grid. Nothing in the simulation knows about networks or paths. Every agent uses only the same four numbers: its position, its heading, the value of the cell a short distance to its left, the value of the cell to its right, and the value straight ahead. Yet thousands of those local decisions add up to a layout that prunes itself toward a few efficient trunks.

The rules

Per frame, each agent samples the trail at three points nine pixels ahead: one straight, one rotated by the sense angle to the left, one rotated to the right. If the centre reading is strongest the heading stays put. If a side is stronger the agent rotates a small step that way. If both sides beat the centre it picks one at random. The agent then walks one pixel forward and adds 0.5 to the cell it landed on. After all agents have moved, the trail is averaged with its eight neighbours and multiplied by the decay factor. Slide the decay up and the veins thicken into puddles, slide it down and the network starves.

Source

The algorithm is from Jeff Jones, Characteristics of pattern formation and evolution in approximations of physarum transport networks, Artificial Life 16:2 (2010), pages 127 to 153. Sage Jenson's 2019 piece physarum is the prettiest implementation I know of, and the colour choice here is a nod to it.