Another Boids in Rust

Description

This is my implementation of the Boids flocking algorithm. It is written in Rust, built on the Bevy game engine, and compiled to WASM to run in the browser.

The algorithm consists of just 3 rules:

From these rules, the flocking behavior emerges naturally.

My version of this program has some extra rules governing speed. In short: things below some threshold are sped up, and things above are slowed down. This is to keep an appropriate amount of kinetic energy in the system. Since the boids start in a circle with the same speed, the sum of all velocity vectors is vec2(0, 0). Technically, floating-point rounding errors would likely mean the system always has some energy, but never enough for an interesting simulation.

Controls

Input Effect
Mouse The scanner circle is attached to the mouse cursor. Move it to scan boids within the radius.
Left mouse button Put scanner into center-of-mass mode
Right mouse button Put scanner into average velocity mode. (There's a window focus bug. This button doesn't work quite right!)

Misc

Source code https://github.com/DerVerrater/another-boids-in-rust
Program Version v0.3.0 (+patches)