Actual integration of this into the website is still in progress, but in the meantime here is the initial version.
This is an early attempt at an implementation of flocking behavior, sometimes referred to as boids.
I would like to remake the logic in the future, because this current implementation
is very buggy.
This project was my first introduction to 2D graphics, and I did not have enough time to research before attempting to implement this. However, it does look quite interesting at first glance.
Future works on this will likely start with a replacement of the Boid class's data members to include a position and a directional vector. Various separation, alignment, and cohesion coefficients will be refactored to apply to the various Boid "species" as opposed to individual Boid instances. Inheritance will be very useful here to define distinct species, while polymorphism would allow for some Boids to be predators, producers, workers, or some other variation. Implementation of a quadtree is high on the priority list for performance reasons, reducing lookup times for all Boids finding a flock from an O(n^2) algorithm to O(nlogn) algorithm.
Perhaps more interestingly, a rewrite would allow me to utilize the 3D capabilities of HTML5, and this could become a 3D simulation relatively easily on the next iteration. In a 3D environment the theoretical quadtree would need to evolve into an octree.
The potential of writing this program in OpenGL so all logic can be carried out in a compute shader is enticing as well, but compute shaders are currently only supported on specific experimental versions of most web browsers.