Task to Complete
Develop a program to simulate the flocking of “boids”. This program must:
- be written using Python
- incorporate the three flocking behaviors: alignment, cohesion, and separation
January 23rd, 2017
- I spent this class mainly doing research about flocking, locomotion, and boid behaviors. I read through the websites provided, as well as some others I found on the Internet.
January 25th, 2017
- I created the program structure today. I have three classes: environment to hold all the boids and display them, boid to simulate the behavior and movement, and vector. The vector class is mainly just to make calculating the forces experienced by the boids easier.
- For this project, I am using pygame to display the graphics. I had to install pygame on my computer, then had to get my program to import pygame. This process took the most time as my python code wasn’t able to find the pygame module; many people in the class experienced similar difficulties. Eventually, I was able to install pygame correctly.
- I wrote a quick sample code to make a window appear with pygame – it worked!
January 27th, 2017
- Today, I wrote the Vector class. It would hold two components, x and y, and have basic Vector operations like adding, subtracting, multiplying by scalars, and such. It would also have methods to determine its magnitude, to scale it, and to truncate it.
- I designed Vectors to be immutable, so all these methods would return a new Vector.
- I also began setting up Boid. Each boid would have its position vector, velocity vector, heading (direction) vector, mass, and maximun speed.
- I also set up Environment. It would contain a list of all the boids. It would also have a method, to be accessed by each boid, to get all the neighbors in its vicinity.
- I then created an update and display method for boid. These would update the boid’s position based on its velocity, and display it at its correct heading and position on the screen. Environment would call these methods for every boid in an infinite loop.
February 7th, 2017
- I also wrote the alignment, cohesion, and separation methods. This process was relatively simple because I had already researched this behavior on the first day.
- I had to do a little bit of debugging as the boids initially were moving around the screen without much control. I later realized that it was because I was accidentally truncating the force vector, instead of the velocity vector, by the maximum speed.
February 9th, 2017
- Today, I wrote the seek and arrive methods for the boid. These would allow it to “follow the leader” – in this case, my mouse cursor. Again, this process was relatively simple due to prior research.
- I spent the rest of the class adjusting the separate weightings of these different methods to make the boids’ flight look more natural.
February 11th, 2017
- Today, I had some spare time so I decided to add some extra behaviors for my boid. These include flee, evade, and pursue.
- I initially added a wander behavior as well, that used Reynold’s circular wandering method to prevent the boid from looking jittery. However, I later removed it because 1) it wasn’t working well with the other methods, and 2) it was taking too much time to adjust to look natural.
- At this point, the program was pretty much complete.