Use the mouse to add boids. Hold space to push boids. This is an optimization on the naive boids algorithm using spatial hashing/binning. For comparison: https://scratch.mit.edu/projects/648774624/ Turbowarp highly recommended as it allows much more boids and better showcases the optimization. This is naturally a bit slower than the unoptimized one, but it can do around 600 boids before bogging down, while the unoptimized version can only do 250 at a similar speed. On Turbowarp this can do over 10k without lagging, while the other takes a couple seconds per frame. Note: dist divisor is s in 1 / ((dist^2 / s^2) + 1), which is the weight of a boid's neighbor. (amount pushed) The optimization is that they don't have to look through all the other boids, because the boids register themselves into bins that they then can look through to find their neighbors. I think it takes O(n log n) to create the hash table, and then O(log n) to look through it (just guessing). The naive way is O(n^2). Please give any suggestions you have on how I could improve this project. If you want to learn more about spatial hashing/binning: https://youtu.be/i0OHeCj7SOw https://www.cs.cornell.edu/~bindel/class/cs5220-s14/spatial.pdf https://www.cs.ucf.edu/~jmesit/publications/scsc%202005.pdf updated Aug 19, 2022: changed how borders work, added speed cap, and added mouse pushing.