Physarum Polycephalum aka slime mold is made up of a vast number of individual single cell organisms. These organisms have no brains or intelligence, but complex behaviors emerge when many of them are put together. Depending on their environment they move like what seems to be a much more complex entity.
Here are some great videos about slime molds with some awesome time lapse footage.
Once you have watched those you should hopefully have a better appreciation for the simple slime mold and the rest of this post will make more sense.
Here is one final video showing time lapse footage of various Physarum
Simulating Slime Molds
Sage was inspired by the paper Characteristics of Pattern Formation and Evolution in Approximations of Physarum Transport Networks.
He gives this simple diagram explaining the steps.
The basic explanation is a bunch of particles move over an area turning towards spots with higher concentrations of a pheromone trail. They also leave a trail as they move. These basic steps create interesting patterns and structures.
Following the principals from Sage and the paper, this is how my take on simulating Physarum works.
1. Create a 2D array that tracks the pheromone trail intensity at every pixel location. Initially all spots are set to 0 intensity. I tried setting various shapes and perlin noise clouds to start, but the moving particles quickly erase any starting shapes and create their own paths so I just start with an empty space. Sage’s examples show interesting patterns and structures when starting with circles or other shapes, so I need to do some more work on start patterns.
2. Create a list of particles with properties heading (direction/angle the particle is moving), x,y (positions), sense angle (how wide the particle looks to the left and right) and sense distance (how far in front the particle looks), turn angle (how quick the particle turns towards the sensed areas). I set the number of particles to match the image width multiplied by the image height. That seems to nicely adjust the particle count when changing image sizes.
3. Main loop
a) Display. For display I scale the minimum and maximum trail values to between 0 and 255 for a gray scale intensity (or to be used as an index into a color palette, but simple gray scale seems to look the best).
b) Each particle looks at the 3 locations in front of it based on the sense angle and distance. You then work out which of the left, front and right spots have the highest concentration of the pheromone trail.
c) Turn the particle towards the highest pheromone intensity. ie if the left spot is highest then subtract turn angle from the particle heading. If the front is highest do not make any change to the particle heading. If the right is highest add turn angle to the particle heading. You can also reverse this process so the particles turn away from the highest pheromone levels.
d) Move the particle forwards by a specified move amount.
e) Eat/absorb. I added a setting so that particles can absorb a bit of the pheromone trail at this point.
f) Deposit an amount of pheromone onto the trail to increase it.
g) Blur the trail array. This simulates the pheromones diffusing over the surface. I use this quick blur with an option for a blur radius between 1 and 5.
h) Evaporate the trail by a small amount. This slowly decays the amount of pheromone.
Repeat the main loop as long as necessary.
See my Physarum Simulations gallery for more images.
Here is a movie with some example results showing the simulations running. For the display the pheromone trail intensities are mapped to a gray scale palette (brighter = higher intensities).
Multiple Species Physarum Simulations
My next idea was to have multiple Physarum types in the same area. For these cases I used 3 sets of Physarum (3 groups of particles with their own unique settings) as shown in the following settings dialog.
Each of the pheromone trail intensities are then converted to RGB color components.
This works but the results are just 3 separate simulations that do not interact. The idea is to have each of the particle types attract to their pheromones, but move away from the other 2 types of pheromones.
The main change is in the pheromone detection and turn code. For the single Physarum simulation the particles look left, forward and right and then turn and move based on the location with the highest pheromone concentration. For 3 particle types they take into account their pheromone concentrations but subtract the pheromone concentrations of the other 2 types. For example if the 3 trail/pheromone arrays are called rtrail, gtrail and btrail, then the red particles pheromones are calculated by using rtrail[x,y]-gtrail[x,y]-btrail[x,y]. The highest concentration of left, forward and right is then turned and moved towards.
More example images can be seen in my Physarum Simulations Gallery.
Here is a sample movie showing some of the multiple species results.
Both single and multiple species Physarum Simulations are now included with the latest version of Visions of Chaos.