Sunday, March 15, 2009

Pygame for Flocking Behavior Simulation


Back in the 80s, Craig Reynolds did some great work on simulating the flocking behavior of birds on a computer. I've always been fascinated by his results, as they look so much like a real flock of birds.

Since then there have been numerous implementations of his approach.

While programming Alice with a student recently, we came up with a way to simulate fish swimming in schools. Our method was nowhere near as complicated as flocking boids, but it was quite effective nonetheless. It merely involved random movement with boundary checking: get too far away from the "center" and the fish decided to head back towards the "center". Of course the "center" here may be a physical location, or the average location of the fish.

To study this in more detail, I decided to use Pygame, a module for Python. Pygame makes writing little graphical simulations a piece of cake. Add to it the functionality of Numpy or Scipy and you have a very powerful environment for scientific simulations.

No comments: