Functional Flocking Quadtree in ClojureScript
lbjgruppen.com·1d·
Discuss: Hacker News
🔓Lock-Free Structures
Preview
Report Post

In a recent blogpost I demonstrated how to build purely functional quadtrees in submilliseconds and this week I’ll take it up a notch and show how to add multiple focal points and add some boid flocking logic.

A demo

Below you should see 200 boids acting as individuals when apart and as flocks when closer together.

How to flock

To build this simulation, assuming you’ve read how to build a functional quadtree, we need only 3 things

  • A way to represent a Boid
  • Some fast way to get it’s closest neighbors
  • Figure out how these neighbors interact

So let’s start with a generous representation of a Boid. I say generous because I’m purposely including more data than needed. The cost is a bit more memory but it makes …

Similar Posts

Loading similar posts...