Skip to content

Ant Colony Simulation

Published:

Ant Colony

While it was very flexible, the format of the first assignment also posed a unique challenge in the repetitiveness of the medium. With the six identical projector panes it was of course necessary to either create something interesting enough to see duplicated six times, or to introduce some kind of variation between the panes. I figured the easiest way to add this variation was either to make a heavily parameterized generative art program, which would then get fed random values for each pane, or to link the physical dimension of horizontal space with some other dimension of the artwork, like color.

The Motivation

For my project I decided that I wanted to create a simulated ant colony. For me at least, from the examples we looked at, the most engaging pieces were those that involved some kind of organic forms, and what better way to lend an organic feel to something than mimicking nature itself. Simulations of the natural world are always fascinating, as they manage to capture the beauty of complex behaviors emerging from a simple set of rules.

The Simulation

The colony is made up of a few different simple parts that come together to loosely simulate the way real ants behave in nature. The rules governing the simulated organisms were inspired by an entry in MathWorld, with a few modifications. The world the ants navigate contains an anthill and multiple food sources. The goal of the ants is to try to find food and bring it back to their hill, so that they can feed the colony. Ants spawn at the anthill and can move around freely, making random course corrections as they go. Once an ant runs into a food source it consumes a small part of it and then tries to find its way back to the anthill. As it makes its return it leaves a chemical trail of “pheromones,” which other ants will be able to trace back to the food in the future. This means that over time the ants will discover short paths to all the food sources. The pheromone map is displayed as it’s laid down using a bright accent color, but fades over time so that old paths are removed. However, you can still see the entire history of the pheromone trails, including the old paths, as a ghostly image displayed in another color in the background, which pulses light and dark. The ants obey a few other rules which make them a little smarter, such as that they gravitate towards food sources when they get close enough to them, but for the most part that’s all it takes to create an interesting simulation.

A portion of an ant colony containing all the important elements (hill, food sources, ants, pheromone trails)

A portion of an ant colony containing all the important elements (hill, food sources, ants, pheromone trails)

The Stack/Technical Challenges

Since this first project is pretty simple, there weren’t too many moving pieces. However, I did run into several challenges when I got to the point of needing to distribute the final product. The actual visualization and simulation is all done using P5js, the javascript version of processing. This is good for portability, because it means that the program can run more or less on any computer that has a browser. It could even be hosted as a website, removing the need for installation at all. However, since ideally you want the installation to just be plug and play, and I still had to worry about the arrangement of the screens, my original plan was to create an executable that would handle window positioning. I thought I would just be able to bundle my website/app using electron, in the .exe format supported by windows, and then transfer that file over to the projector computer. This would have made installation very quick and easy, but several obstacles presented themselves.

Problems With Electron

The most basic problem turned out to be the lack of administrator permissions on the projector computer. Since I was unfortunately unable to cross compile the app for windows using my mac, I had been thinking I would use the PC itself to compile it, since its a pretty simple process. After compiling, I would have ended up with an executable that could be run without any hassle, sort of bootstrapping in a way. However, in order to compile an electron app you need NodeJS installed, which is unfortunately missing from the PC, and you can’t install it easily without admin permissions. This meant I had to scrap the idea of using electron entirely. Even if it had worked, though, I discovered that performance of the javascript canvas is significantly worse in electron than in a usual browser. This probably means that the browser is better able to utilize the full resources of the host computer anyway. What I ended up with in the end turned out to be simple enough that I believe even an untrained operator could figure it out, following the setup guide in the GitHub. The program is basically just split up into two browser windows instead, which are then full-screened to fill both of the big combination displays.

General Performance

The performance issues that I ran into unhappily weren’t limited to problems with electron. The simulation looks the best, and the most organic when it has the most detail. But, of course, a large simulation size also comes with a large resource requirement. Processing just doesn’t seem fast enough to handle this challenge in real time, so I was forced to downsize somewhat, and reduce the granularity of some elements, such as the pheromone map. The output is still pretty mesmerizing, but if I really wanted to realize the full potential of this idea I would have to rewrite my program using a faster system.

Nice Surprises

As is usual the case with art, especially the generative kind, there were several happy accidents along the way. First of all, the pheromone map, which I had originally intended to consist of actual path lines instead of dots, ended up looking much more visually interesting as it is. The size of the dots turned out to be a good way to represent the strength of different signals, and provides insight into how the system works at a mechanical level. The biggest discovery, though, was the way that the ant paths make these sort-of spiral arms as they return to the anthill. This is due to the simple fact that the ants are only allowed to turn by so much in any given space of time, giving them a turning radius, making them loop around on their way back.

Video Evidence



Previous Post
Tune Player