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...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help