The Artist's Husband: Behavioral Animation

/2020/09/the-artists-husband-boids/images/_SSB2171.jpg

This week I wanted to talk about something a little different, something only peripherally related to art: Behavioral Animation. Behavioral Animation is a kind of computer animation in which an autonomous object determines its own actions by interacting with its environment according to certain rules. Behavioral Animation is a fairly vague term, which covers quite a bit of ground.

The Game of Life

A simple example is The Game of Life, developed by John Conway , a British mathematician, in the early 1970s. The game starts with an infinite grid (well, potentially infinite – please don’t try to draw an infinite grid…) with some of the squares filled in. It’s important to notice that each square is surrounded by eight additional squares. Nothing surprising there, it’s just how grids work! Then the squares are modified according to two simple rules: 1) if square that is filled in has either two or three of its eight neighboring squares filled in, then it remains filled in, otherwise it is emptied. 2) if an unoccupied square has exactly three filled in neighbors, then it is filled in. This continues through successive generations. The interesting thing about this is that is mimics population growth. Consider each square to be a living cell if it is filled in. If the cell doesn’t have enough neighbors, it dies (perhaps of loneliness.) If it has too many neighbors, it dies (perhaps for lack of resources.) If conditions are just right, they can reproduce, and new cells appear (we’ll just gloss over the fact that that takes three neighbors, not two!) It turns out this models things like bacterial growth fairly well.

Depending on what the starting pattern looks like, successive generations may grow, shrink, stabilize, or growth legs or wings and take off across the infinite grid. Random starting patterns can grow (or shrink) in surprising and intricate ways. The image below is an example of a complex pattern that crawls across the grid leaving patterns which themselves emit patterns take take off across the grid.

/2020/09/the-artists-husband-boids/images/Conways_game_of_life_breeder_animation.gif

John Conway was a brilliant mathematician who, while well known for The Game of Life, made contributions in many fields of math and physics. Sadly, he passed away in April from COVID-19.

Boids

Of course, different rules can be used, and there have been different pattern generating systems modeled after The Game of Life. In the early 1980s, Craig Reynolds was working on graphics for movies such as Tron , and was looking for ways to reproduce life-like swarms of animals. He developed the first realistic computer model of flocking birds. His algorithm, called Boids , was first used in the 1992 film Batman Returns to generate not only swarms of bats, but penguins marching through Gotham City. Reynolds won an Academy Award for pioneering contributions in the area of 3D computer animation in 1998 .

Boids works by applying three basic rules to individual boid objects: separation, alignment and cohesion.

Separation

/2020/09/the-artists-husband-boids/images/Rule_separation.gif

The separation rule requires a boid to change direction to avoid collisions with its neighboring boids. This tries to maintain a boundry around each boid.

Alignment

/2020/09/the-artists-husband-boids/images/Rule_alignment.gif

The alignment rule requires a boid to fly in the same average direction as its neighboring boids. A lone boid travelling some direction will join any flock that it sees.

Cohesion

/2020/09/the-artists-husband-boids/images/Rule_cohesion.gif

The cohesion rule requires a boid to try to fly to the center of its neighboring group of boids. This keeps the boids from getting to far apart.

There may be other rules added, such a avoiding collisions with other objects (such as buildings or trees) or seeking a particular goal, perhaps by chasing another kind of object, but the first three are key. The results are surprisingly realistic and so complex as to be unpredictable.

Each boid only considers its immediate neighbors, as shown by the circles in the images above. The unpredictability of the paths of each boid comes from the fact that each boid has neighbors and each of those neighbors also has neighbors which may not be neighbors of the first boid. So there is a constant interplay of forces acting on each boid.

Boids is a favorite practice project for graphics programmers, and there are examples all over the internet in pretty much any programming language you care to use. In my past posts, I have used Javascript and the p5.js library. There is an example implementing Boids in the p5.js documentation.

/2020/09/the-artists-husband-boids/images/boids.gif

So next time you need to generate a swarm of objects for your art project, look to behavioral animation for a solution. Have fun!

P.S. The bird at the top of this post is for decoration only! It is not a boid that I generated, it’s a real bird that I photographed near Tucson, AZ in 2010. I chose it because this post was originally just supposed to be about Boids. In hindsight, it’s a poor choice, since hawks don’t flock, but they are far more photogenic than starlings!