
Boids - jonbaer
https://en.wikipedia.org/wiki/Boids
======
matsemann
I have an implementation here [0] if people want to play with it. Supports
dynamically changing the controls, has obstacles and predators. Setting
weights for separation, alignment and cohesion to zero and then increasing
only one of them nicely shows which role each of them plays. It's actually
made as a workshop [1] for my company, where the shell is provided and one has
to implement it step by step. In Norwegian, though.

Update: Dang linked other discussions, and I see I commented on one from 2015
[2]. Someone there asked for the course content, and that's available (in
English!) in a PDF in [1]. This workshop/implementation is actually an example
of what I wanted the students to make at the time. Which I then retrofitted to
a fun workshop for my colleagues.

[0]: [https://matsemann.github.io/boids-
workshop/](https://matsemann.github.io/boids-workshop/) [1]:
[https://github.com/Matsemann/boids-
workshop](https://github.com/Matsemann/boids-workshop) [2]:
[https://news.ycombinator.com/item?id=9300142](https://news.ycombinator.com/item?id=9300142)

~~~
parhamn
I had fun playing with the parameters, thanks! Now, I want a wallpaper version
of this with low maxSpeeds. Very relaxing.

~~~
w-ll
Remember when Windows allowed you to set a .html file as a desktop background.

Wallpaper Engine [0] might be your next best bet.

0\.
[https://store.steampowered.com/app/431960/Wallpaper_Engine/](https://store.steampowered.com/app/431960/Wallpaper_Engine/)

------
timtimmy
Boids are my favourite hello world for 3D simulation environments. For the
last few weeks, I've been using boids to update my GPU programming skills and
knowledge of related algorithms in Unity and Unreal.

Yesterday I got 0.5 million boids simulating in Unreal Engine at 45 fps on a
GTX 1080 [0]. The bottle neck is rendering so many instanced cone meshes, the
simulation without rendering can do 1 million boids at 120 fps. I'm borrowing
a common data structure used in GPU fluid simulations, the dynamic hashed
grid, to calculate the neighbourhood of each boid (cool tutorial here with
full source code [1]). We need the neighbourhoods to calculate their urges. My
code is a mess at the moment, but if there is interest I can post it to GitHub
(Unity and Unreal).

Boids are an example of agent-based modelling and swarm systems. I used agent-
based modelling in my PhD thesis to construct and simulate realtime,
interactive 3D biomolecular models of mitochondria and neuromuscular synapses
[2,3]. Now that I'm free (graduated), I'm building an iPad app to teach and
communicate structural and molecular biology with immersive, and realtime
simulations. Our vision is to make molecular and structural biology immersive
and fun. It's not a textbook, it's a little more like Neil Stephenson's young
lady's illustrated primer! :D

[0]:
[https://twitter.com/timd_ca/status/1243941167005192192?s=20](https://twitter.com/timd_ca/status/1243941167005192192?s=20)

[1]: [https://wickedengine.net/2018/05/21/scalabe-gpu-fluid-
simula...](https://wickedengine.net/2018/05/21/scalabe-gpu-fluid-simulation/)

[2]:
[https://prism.ucalgary.ca/handle/1880/111493](https://prism.ucalgary.ca/handle/1880/111493)

[3]: [https://youtu.be/6CsxADBpal0](https://youtu.be/6CsxADBpal0)

~~~
gfxgirl
It wasn't Unreal Engine that gave you that perf. It was your GTX 1080. Unreal
Engine (or any Engine) in this situation is doing next to nothing.

Sorry it's just this kind of thing pushed my buttons. I see someone showing
their engine and claiming perf when their example is 99.999% GPU and 0.001%
anything to do with their engine.

~~~
timtimmy
Sorry, I didn't mean to mislead you. This has little to do with Unreal (or
Unity) and everything to do with GPU programming.

------
diggan
If you're in 3D animation/modeling/whatever and have a little bit of
experience, Blender has a pretty stable simulation of Boids that is lots of
fun to play around with. It's been built-in into Blender since... For as long
as I remember, and it has lots of properties you can play around with, and you
can also make the boids be rigid bodies as well so they can interact with
other elements in your scene.

Some links if you want to try it out:

\-
[https://docs.blender.org/manual/en/latest/physics/particles/...](https://docs.blender.org/manual/en/latest/physics/particles/emitter/physics/boids.html)

\- [https://www.blendernation.com/2019/07/06/how-to-use-boids-
in...](https://www.blendernation.com/2019/07/06/how-to-use-boids-in-
blender-2-8/)

\- [https://www.blendernation.com/2008/01/05/simulating-
flocks-h...](https://www.blendernation.com/2008/01/05/simulating-flocks-herds-
and-swarms-using-experimental-blender-boids-particles/)

\-
[http://feeblemind.tuxfamily.org/blog/index.php?post/2007/12/...](http://feeblemind.tuxfamily.org/blog/index.php?post/2007/12/28/106-setting-
a-prey-predator-relationship-using-boids-particles)

~~~
jedimastert
For even more Blender boid related fun, here's Ian Hurbert's ",lazy tutorial"
for animating moths. He's fun

[https://youtu.be/imkSdlbXB_U](https://youtu.be/imkSdlbXB_U)

------
DonHopkins
I've confirmed with Craig Reynolds that yes indeed, then name of Boids was
inspired by The Producers:

[https://www.youtube.com/watch?v=aL6mTMShVyk](https://www.youtube.com/watch?v=aL6mTMShVyk)

>"He's up on the roof with his boids. He keeps boids. Doity, disgusting,
filthy, lice ridden boids." -The Concierge, not a Madam

~~~
rootbear
I had no idea! I would have guessed it was a contraction of "bird-oid", or
something like that.

~~~
DonHopkins
That too, but it's only the cover story for people without a New York
Metropolitan accent!

[https://en.wikipedia.org/wiki/Boids](https://en.wikipedia.org/wiki/Boids)

>Boids is an artificial life program, developed by Craig Reynolds in 1986,
which simulates the flocking behaviour of birds. His paper on this topic was
published in 1987 in the proceedings of the ACM SIGGRAPH conference. The name
"boid" corresponds to a shortened version of "bird-oid object", which refers
to a bird-like object. Incidentally, "boid" is also a New York Metropolitan
dialect pronunciation for "bird".

------
gdubs
I recently implemented boids in a compute shader [1]. It’s using Apple’s Metal
framework, and rendered in 3D. The boids are simple triangles, and I added a
bit of specular shading to give them a little bit of a “shimmer” as they
flock.

I implemented an NVIDIA algorithm for running n-body simulations on the GPU.
The constraint is memory access, which can freeze up in a case like this. [2].
Converting from CUDA to Metal wasn’t too bad.

1:
[https://www.instagram.com/p/B4t4ewCplfR/?igshid=1uxnng6idsqb...](https://www.instagram.com/p/B4t4ewCplfR/?igshid=1uxnng6idsqb8)

2: [https://developer.nvidia.com/gpugems/gpugems3/part-v-
physics...](https://developer.nvidia.com/gpugems/gpugems3/part-v-physics-
simulation/chapter-31-fast-n-body-simulation-cuda)

edit: Here's a low-res animated GIF for anyone who doesn't want to click an
instagram link:
[http://gregorywieber.com/assets/images/art/murmuration.gif](http://gregorywieber.com/assets/images/art/murmuration.gif)

~~~
afro88
Love it, and the others on your instagram. You should start a dedicated
account for them. I would like to follow your art, but feels weird seeing
family photos of someone I don't know :/

------
anotheryou
Beautiful example:

[https://twitter.com/OskSta/status/1219340987299966976](https://twitter.com/OskSta/status/1219340987299966976)

[https://twitter.com/OskSta/status/1219343599336333319](https://twitter.com/OskSta/status/1219343599336333319)

[https://twitter.com/OskSta/status/1225037781858234368](https://twitter.com/OskSta/status/1225037781858234368)

~~~
mshafer
Oskar’s tweets showing his city-builder are some of my favourite things on the
internet. His combination of 3D rendering and artistic style is just black
magic to me.

~~~
anotheryou
A real challenger to the Return of the Obra Din Devlog :)

[https://forums.tigsource.com/index.php?PHPSESSID=qvfvkcqtfr9...](https://forums.tigsource.com/index.php?PHPSESSID=qvfvkcqtfr9q3kb2rtlqj3j3c1&topic=40832.20)

------
jaltekruse
Might be a dumb thing to post on hacker news, but I tried using the word boid
or boids in Scrabble and my competitive wife wouldn't let me because it wasn't
in the dictionary. It fit so well too!

~~~
banana-slug
You need a better dictionary: [https://www.merriam-
webster.com/dictionary/boid](https://www.merriam-webster.com/dictionary/boid)

Long before the flocking model, “boid” referred to snakes of the Boidae
family, like boas and anacondas.

~~~
contingencies
Previously we played with the Australian reference, the Macquarie Dictionary.
Subsequently, as an international family finding that an expensive and static
resource insufficiently engaged with international usage we began to play
admitting anything in either dictionary.com or wiktionary with an English
entry, excepting proper names and non-naturalized acronyms. As official
scrabble cheat words cover a lot of random Scots/Welsh, you might choose to
permit those (single result page on Wiktionary). It starts to get ridiculous
fast. I personally love the learning aspect and we do not play the traditional
"challenge" rule, in fact we actively encourage consultation of reference
works before and after each play. I am a big fan of Wiktionary, occasionally
adding to existing English and Middle Chinese entries.

For example, according to Wiktionary, _boid_ (and its plural) should be
permitted under etymology two, ie. _member of the family Boidae of non-
venomous snakes_ or etymology three, ie. _Nonstandard spelling of bird
representing the New York City pronunciation_. We would not permit it under
etymology one (computer program name). Now look - you learned something!
[https://en.wiktionary.org/wiki/boid#English](https://en.wiktionary.org/wiki/boid#English)

------
qubex
I recommend one of my favourite books, Gary William Flake’s 1998 _The
Computational Beauty of Nature_ to anybody interested in boids or other
computational models of social, chemical, and physical phenomena.

Therein the author covers boids extensively and in detail. If I am not
mistaken it is in section 16.3 that the author treats boids fairly
extensively.

~~~
jonbaer
He just did a great interview @ [https://podcasts.apple.com/us/podcast/gary-
flake-scientist-a...](https://podcasts.apple.com/us/podcast/gary-flake-
scientist-author-former-cto-search-at-salesforce/id1480732807?i=1000469330999)

------
jonbaer
Boids in 3D Unity:
[https://github.com/SebLague/Boids](https://github.com/SebLague/Boids) and the
excellent related video
[https://www.youtube.com/watch?v=bqtqltqcQhw](https://www.youtube.com/watch?v=bqtqltqcQhw)

~~~
juanuys
Does it use the GPU?

[https://github.com/SebLague/Boids/blob/master/Assets/Scripts...](https://github.com/SebLague/Boids/blob/master/Assets/Scripts/BoidCompute.compute)

If so, then awesome :)

------
dang
Related from 2015:
[https://news.ycombinator.com/item?id=9298338](https://news.ycombinator.com/item?id=9298338)

2011:
[https://news.ycombinator.com/item?id=2504652](https://news.ycombinator.com/item?id=2504652)

2014:
[https://news.ycombinator.com/item?id=7293350](https://news.ycombinator.com/item?id=7293350)

One comment from 2018:
[https://news.ycombinator.com/item?id=17167077](https://news.ycombinator.com/item?id=17167077)

(Links for the curious. Reposts are ok after a year:
[https://news.ycombinator.com/newsfaq.html](https://news.ycombinator.com/newsfaq.html))

------
juanuys
I made a Three.js boids implementation for an interview once. The role was for
web dev, but the theme was "come and teach us about something that interests
you" :)

[https://github.com/juanuys/boids](https://github.com/juanuys/boids)

------
robotresearcher
Reynolds put up a page about Boids in 1995 and added links to related work for
a few years. Great stuff.

[https://www.red3d.com/cwr/boids/](https://www.red3d.com/cwr/boids/)

------
bschne
Dan Shiffman over on The Coding Train has a nice walkthrouhg of implementing
this in P5.js

[https://www.youtube.com/watch?v=mhjuuHl6qHM](https://www.youtube.com/watch?v=mhjuuHl6qHM)

~~~
mar77i
Recently did that code as presented using pygame, but I haven't uploaded it
anywhere yet, that might be a good idea, though.

------
simonswain
I did a browser based Boids version that simulated galactic colonization:
[https://coldwar.io/deepspace](https://coldwar.io/deepspace) and a simpler
variant with predators:
[https://coldwar.io/predators](https://coldwar.io/predators)

------
jzting
I also have an implementation [0] that shows the paths of the boids. Based on
the parameters, some very interesting patterns emerge!

[0] [http://jzlabs.com/](http://jzlabs.com/)

------
foreigner
Good old Boids! I implemented a clone of Boids in C as my senior project in
high school. It included 3D wireframe graphics from scratch. My teacher said
it was "A nice screensaver".

------
mehmetoguzderin
WGSL [0] implementation of Boids:
[https://dawn.googlesource.com/tint/+/refs/heads/master/test/...](https://dawn.googlesource.com/tint/+/refs/heads/master/test/compute_boids.wgsl)

[0]:
[http://gpuweb.github.io/gpuweb/wgsl](http://gpuweb.github.io/gpuweb/wgsl)

------
escot
> Incidentally, "boid" is also a New York Metropolitan dialect pronunciation
> for "bird".

------
glouwbug
StarCraft 2 used boids, and I'm using boids to rewrite Age of Empires II:

github.com/glouw/openempires

~~~
marktangotango
I’ve often pondered the feasibility of using boids (or a boid like rule
system) to implement ancient combat formations like pike squares skirmish
lines. Is that what you’re doing?

~~~
glouwbug
Yes, though I'm not at the formation stage just yet. Boids just know how to
stear organically much like Zerglings do.

Boids just provide distancing at the micro level. Astar or Greedy First Best
at the macro level ultimately provides the boid with a final destination, and
the boids organically work together on path to their respective final
destinations.

Rise of Nations did it almost perfectly in the early 2000s with left box drag
for selection and right box drag for retangular placement. Rome Total War
upped the antics a bit with 10,000 unit scales over Rise of Nations 200 unit
scales, but suffered some serious bugs. In my opinion no one except Julius
Caesar can "program" so many units to properly do their bidding!

------
miniatureape
I posted this simple boid drawing toy a year or two ago:
[https://miniatureape.github.io/boiddraw/](https://miniatureape.github.io/boiddraw/)

------
ur-whale
Slightly OT, but this is a _very_ interesting problem to implement on a GPU
because it very much resembles in its structure the implementation of exact
N-body simulator on massively parallel machines.

~~~
glouwbug
Yes boids are great for parallelization. Each boid must compute a stressor
imposed by neighboring boids based on the three rules in the paper
(separation, alignment, and drifting towards center of mass). The stressor for
each boid is simply applied to each boids velocity. Given a thousand threads /
cpus / cuda cores, what have you, each unit can be applied to a single boid

------
anoopelias
Now who doesn't have an implementation of Boids of their own... :)

[https://anoopelias.github.io/boids/](https://anoopelias.github.io/boids/)

~~~
postnihilism
It's a classic :)

I made a little framework for building these types of models:
[https://github.com/jrhdoty/SwarmJS](https://github.com/jrhdoty/SwarmJS)

Here's a boids implementation using it:
[http://jrhdoty.github.io/SwarmJS/](http://jrhdoty.github.io/SwarmJS/)

------
dimovich
My simple implementation in C / ClojureScript.

[https://dimovich.github.io/art/](https://dimovich.github.io/art/)

------
banana-slug
Nice boid-related tutorial:
[https://www.youtube.com/watch?v=bqtqltqcQhw](https://www.youtube.com/watch?v=bqtqltqcQhw)

------
jonbaer
[https://github.com/search?q=boids](https://github.com/search?q=boids)

~~~
banana-slug
Note that this one
([https://github.com/meshula/OpenSteer](https://github.com/meshula/OpenSteer))
is the “semi official” port of OpenSteer, a library for steering behaviors,
which is the generalization of the ideas underlying boids, as described in
[http://www.red3d.com/cwr/papers/1999/gdc99steer.html](http://www.red3d.com/cwr/papers/1999/gdc99steer.html)

------
jbverschoor
I remember boids was one of the example programs with the direct3d sdk back in
the ‘90s

------
diekhans
It is a beautiful paper, well worth reading the original.

------
jsilence
Could that be used to simulate the pandemic?

~~~
pinkfoot
#3Blue1Brown has decent (simple) SIR epidemic simulation

[https://youtu.be/gxAaO2rsdIs](https://youtu.be/gxAaO2rsdIs)

~~~
timtimmy
It's a great video. His source is here:
[https://github.com/3b1b/manim/blob/shaders/from_3b1b/active/...](https://github.com/3b1b/manim/blob/shaders/from_3b1b/active/sir.py)

