Concept
This sketch uses a hidden “trail map” where agents deposit pheromones. Every frame, that map is blurred and faded to simulate evaporation, creating organic, vein-like structures. It’s basically a simulation that mirrors the collective intelligence of slime mold. Instead of pre-programmed paths, the visuals emerge from 3,000 agents acting as a decentralized hive mind. I was inspired by the generative work of Sage Jenson and the research of Jeff Jones, who demonstrated that simple chemo-attractant rules could solve complex pathfinding problems.
Code Highlight
The “brain” of this simulation is the Sensory Sampling Logic within the Agent class. The cellular automata part is the sampling of the pheromone trail at three specific offsets—left, center, and right—the agents effectively “smell” their way through the environment.
// THE SENSORY BRAIN
step() {
// 1. SENSE: Check three points ahead (Left, Center, Right)
let v1 = this.getSensorValue(sensorAngle); // Left
let v2 = this.getSensorValue(0); // Center
let v3 = this.getSensorValue(-sensorAngle); // Right
// 2. STEER: Move toward the strongest pheromone scent
if (v2 > v1 && v2 > v3) {
// Stay straight if the center is strongest
} else if (v2 < v1 && v2 < v3) {
// Randomly turn if both sides are better than the center
this.angle += (random() - 0.5) * 2 * turnSpeed;
} else if (v1 > v3) {
this.angle += turnSpeed; // Turn Left
} else if (v3 > v1) {
this.angle -= turnSpeed; // Turn Right
}
// 3. MOVE & DEPOSIT
this.x += cos(this.angle) * moveSpeed;
this.y += sin(this.angle) * moveSpeed;
trailMap[floor(this.x) + floor(this.y) * width] = 1;
}
Milestones and Challenges
This was the first successful implementation of the Agent and Trail Map interaction, created before the sophisticated steering logic was added. In this early iteration, the agents move in straight lines with a small amount of random jitter, leaving behind diffused pheromone trails. It was so I can verify that the trail map processing (diffusion and evaporation) is functioning correctly without the complexity of pathfinding.
This is where the agents stop acting like random dust and start acting like a colony. It’s where an agent could “smell” the trails in front of it and turn toward the highest concentration.
At this stage, the visuals shifted from chaotic, straight lines to the first recognizable “veins” and “rivers.” However, the challenge here was Tuning the Senses. If the sensors were placed too far apart, the agents would spiral uncontrollably. If they were too close, the networks would never merge.
Reflection and Ideas for Future Improvements
This project shifted my thinking toward cellular automata as a tool for art. It’s more powerful than standard steering because the “rules” exist both in the agents and the environment. In the future, I want to implement Multi-Species Slime, where two different colors of agents compete for space, or even incorporate logic where agents must navigate around moving “obstacles” to simulate real-world traffic optimization.