Functional Flocking Quadtree in Clojurescript
Key topics
Diving into the mesmerizing world of simulated bird flocking, a ClojureScript implementation using quadtrees has sparked a lively discussion. Commenters are exploring the generalizability of quadtrees to higher dimensions, with some noting that while the same splitting approach can extend to arbitrary dimensions, alternatives like k-d trees are often preferred. The conversation also touches on the broader applications of quadtrees and related data structures in physics simulations and research. As one commenter points out, even simple implementations can achieve impressive performance with modern GPU acceleration.
Snapshot generated from the HN discussion
Discussion Activity
Moderate engagementFirst comment
6d
Peak period
8
144-156h
Avg / period
4
Key moments
- 01Story posted
Dec 16, 2025 at 5:26 AM EST
18 days ago
Step 01 - 02First comment
Dec 22, 2025 at 2:31 AM EST
6d after posting
Step 02 - 03Peak activity
8 comments in 144-156h
Hottest window of the conversation
Step 03 - 04Latest activity
Dec 23, 2025 at 10:14 AM EST
10 days ago
Step 04
Generating AI Summary...
Analyzing up to 500 comments to identify key contributors and discussion patterns
Want the full context?
Jump to the original sources
Read the primary article or dive into the live Hacker News thread when you're ready.
And the algorithms to solve these quickly is another deep area of research.
In no particular order:
- the original boids code didn't cap the magnitude of acceleration after adding all the contributions; it added the contributions _by priority_, starting with separation, and if the max acceleration was exceeded it didn't add the others
- the max acceleration was decided by adding the _magnitudes_ not vectors of components, so the cohesion vector and the separation vector wouldn't cancel out - separation would win. I think this is why both this and the p5js one form very tight clumps which later "explode". That's this bit of the code (from https://www.red3d.com/cwr/code/boids.lisp):
- this implementation, unlike the p5js version it's based on, caps the acceleration _twice_ - before adding the contributions and after https://github.com/LauJensen/practical-quadtree/blob/7f5bdea... (this is the 'after' bit) - the original had different radii for different components (the separation threshold was 4, the cohesion, alignment thresholds were 5)I've not yet mucked with the rules to see if the behaviour recovers, but the p5js version makes it easy to hack on https://editor.p5js.org/pattvira/sketches/v_tmN-BC5 - as a first change, in draw() in sketch.js change the print statement to this:
... and the two loops below it to use 'boids.length' not 'num'. Then the thing will dynamically adjust the number of boids to give you an acceptable framerate.The reason that the flocks are tight is because the separation "force" is normally computed as a repulsion between a target boid and all other nearby boids individually, not vs. the center of mass of all nearby boids.
https://news.ycombinator.com/item?id=46147341