Intro

I was looking around at some old code I have at my github, and I found an old project of mine to simulate flocking of bird like object or boids. With how clean Go’s build system is, it was really simple to clone the repo, and running go run main.go and the simulation begins, even after 2 years. I made this the summer before I started my freshman year at Carnegie Mellon University. It’s interesting to see a relic of my coding journey and reliving it as a Junior now.

Background

Boid simulation aim to simulate the complex behavior of flocking animals from simple rules that’s really easy to grasp. Another idea that has this principle is the more popular Conway’s Game of Life.

The three core ideas to create boids are Alignment, Cohesion, and Separation.

Alignment

This rule says that a boid will try to face the same general direction as nearby boids. This rule encourages boids to move in the same direction. Initially, all boids will be moving in a random direction, but overtime you should see a continuous movement between groups of boids.

Cohesion

This rule says that a boid will try to move to the center of nearby boid positions. This rule forces boids to stick together. This encourages boids to appear more as a flock. With only the alignment, birds may be facing the same direction but are not close together.

Separation

This rule is like the opposite of Cohesion. Boids that are close to each other will try to move away from each other. This rule is to encourages the objects to make their own space. Without this rule, the boids would more or less be on top of each other. In real life, birds keep some distance from each other.

Conclusion

These three simple rules help to create complex formations and systems. Checkout the github repo to see how this was done using Go and a simple graphics library(Ebiten).