The Boids and the Trees

I have recently been binge watching The Coding Train by Daniel Shiffman. In two of his videos he creates a flocking simulation and a Quadtree. I thought it would be a good excercise to try and combine the two concepts.


I was fairly happy with the result. You can play around with the simulation here:

There is also another amazing YouTube channel by Sebastian Lague where he creates 3D boids with collision detection.


A list of an improvements I want to make in the future.

  • Sliders for simulation variables (perception radius, cohesion/alignment/seperation factors, speed, etc)
  • Better quadtree performance by having it be incremental (only update a boid in the tree once it’s left it’s boundary)
  • Improved interaction
  • Wrap the range checks on the quadtree to have it emulate a “sphere” instead of disjoint space.