Understanding the Physarum Simulation
02.08.2024
Scroll to read on
This is a Physarum Simulation. The first time I encountered it on Sage Jenson's site , I was captivated by its complexity. I asked myself, how can someone code something like this?
Let's zoom in! The white trails on the screen result from the agents' movements. While not visible, the agents are the ones creating these intricate patterns.
Let's render the agents only as a purple dot, a visual marker for the agents' positions and movements.
Now, we see both the agents and their trails rendered together.
So, how does an agent decide where to go? They have a sensor that senses only the trail, not other agents. It samples its surroundings and reveals which direction is more attractive.
After sensing the attractive direction, they step into it. When they take a step, they leave a new trail behind, which diffuses out with time.
A handful of agent properties achieve the emerging patterns. Let's look at three of these properties.
1: Sensor Angle. Go ahead and interact with the eyes of the sensor angle parameter.
Let's play with it when there are other agents as well.
2: Sensor Range. We can change how far an agent can see within the 'trail realm' by dragging the dotted line up and down.
3: Step Size. If you pull the legs apart or closer to each other, we can adjust how far an agent can move.
From these 3 little changes, we witness the emergence of seemingly complex patterns. It's truly inspiring to see how each agent's decision on where to go next in every frame contributes to the beauty of these patterns. The End.
The algorithm is based on the paper "Characteristics of Pattern Formation and Evolution in Approximations of Physarum Transport Networks" by Jeff Jones . There's a parameter called "rotation angle" in the paper which I have left out. This parameter determines how much an agent can turn after detecting the trail. I omitted it because I couldn't find a suitable way to incorporate it. The sensing process is described in a simplified manner. When sensing the trail, only three points are sampled: front, left, and right.
If you are looking for more resources, you can check out the following links:
Morphogenesis Resources by Jason Webb
Coding Adventure: Ant and Slime Simulations
p5.js Coding Tutorial | Slime Molds (Physarum)
Thank you, Raph , for brainstorming with me about the agent's appearance and for p5 support!
This blog post is inspired by the works of pudding.cool and Zeit Online.