the gorgon lab

an exploration of swarm behavior

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:

  1. Fear: Avoid predators by steering away from any predators close to you. When afraid, swarm members will steer and swim at faster than their standard speed. Swarm members following this rule render as a dark red.
  2. Separation: Avoid collisions by steering away from the centroid of visible neighbors within an immediate “repulsion zone”. Swarm members following this rule render as a dark yellow.
  3. Alignment: Try to fly with your visible neighbors, steering towards the average heading of visible neighbors in your wider “alignment zone”. Swarm members following this rule render as a dark green.
  4. Cohesion: Try to fly towards your other flock mates, steering towards the centroid of visible neighbors in your broad “attraction zone”. Swarm members following this rule render as a light blue.

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!