I’ve long been fascinated by swarm behavior - flocks of birds, swarms of insects, ant colonies. It’s incredible how very simple local rules of interaction between large numbers of objects can lead to complex global patterns. I’ve long wanted to explore swarm behavior and play with different configurations for local behavior and how they might affect the rise of global patterns. This visualization was a first attempt at that exploration.
The swarm members, rendered as little triangles, travel generally at a consistent speed, a motion I refer to as “swimming”. They also rotate generally at a consistent rotational speed, a motion I’ll refer to this rotation as “steering”. To decide how to move, each step, the swarm members follow an algorithm similar to the Boids program, following these rules in priority order:
The result is a swarm pattern similar to that of a school of fish. The swarm forms into small groups of tightly packed members, who stay a steady distance apart. When these groups come into contact with each other, they either combine if their contact is gentle, or disrupt each other and form new groups. Over time, the end result is generally a single swarm or two, swimming in a constant direction.
I’ve also made it so you can play with the angular visibility range with the “Visibility” control. This allows you to change at what angle the swarm member can see it’s neighbors. You can see these visibility zones rendered by changing the “Draw Zones” heading to “yes”. At different angular visibility ranges, the swarm pattern evolves differently, demonstrating how small variations in these local rules can result in wide variations in global patterns.
To introduce “predators” and disturb the swarm, click on the canvas. The swarm will behave as though a predator is at that location for a half-second, disrupting any grouped swarms and emulating the behavior of tapping the glass on a fish tank.
Hope you enjoy!