The Boids algorithm, developed by Craig Reynolds, demonstrates that complex flocking behavior in birds emerges from just three simple rules: cohesion (flying toward the center of mass), separation (avoiding collisions with nearby birds), and alignment (matching velocity with neighbors). Each bird makes independent decisions based on these local rules, yet the collective result appears as a unified, coordinated movement resembling a single organism. This illustrates how emergent complexity can arise from simple individual behaviors in decentralized systems.
The Mathematical Secrets of Bird Flocking and Murmurations
Added:I don't know why, but every day in that tree right there, birds congregate together and then at some point they lift off and they start flying together in a flock. You got all these birds that are just moving almost like they're a macro organism. You've got like one individual bird and it'll be leading the pack and then when it turns the other ones turn. It's just a fascinating thing this flock behavior of birds. Today on Smarter Everyday I want to talk about that. It has to do with a mathematical algorithm called Void's algorithm. And I've got a computer scientist buddy named Ben Eater who's going to walk us through that by showing us the map. Oh my goodness.
You can't see it on film yet because of the pixel resolution, but there is a ton over there. And they're all coming to meet right here. Oh, boom.
And we're off. Okay, they went about a mile down the road. Let's go look at them.
We're going to see if we can see them.
There they are.
Try to do this safely here.
And we'll go to the service road just off of the interstate.
Oh man, this is what I normally see every day.
Let's just watch the birds. When you're watching them, think about it at the bird level, like one individual bird, and think about it from the perspective of the whole flock. It's beautiful. And you can see like it's almost like fluid flowing. And you can see like areas of high pressure or high bird density, areas of low bird density. It's beautiful. I'll quit talking now. Let's just watch birds cuz they're cool.
[Music] Every single bird is making decision.
isions based on a very simple set of criteria.
So, I've watched the birds in this specific location for years, and I love it. It's magical every time. But I've recently learned that this is an example of what's called emergent behavior. The decisions of a single bird, when thrown in the mix with the decisions of a myriad of other birds, creates this beautiful aerodynamic dance. I didn't fully understand how this works in flocking birds until recently when I was at my friend Ben Eaters's place out in California. Ben designs and builds his own computers from the individual electronic components demonstrating how these simple components are combined to make complex modern computers. Ben Eer is an amazing programmer with a YouTube channel you should definitely check out.
And there's an algorithm uh that simulates flocking behavior in birds.
Oh, really?
Which is called the Boyds algorithm.
Like a bird void object. Okay.
Or sounds like a New Yorker saying bird.
Okay.
Um, so you're about to I built this.
What? I didn't need to see this.
No, you haven't seen this before.
No.
So, this is just an implementation of the void's algorithm.
Oh, okay. Okay. So, it's it's very difficult, but like I'm tracking some of them and they are kind of gravitationally pulled towards the other one. Is that what I'm seeing?
Yeah. So, there's actually three things going on here. So, let me show you what they are.
Is this how actual birds work?
Quite possibly.
Really? Yeah. Uh, so they're they're doing a couple things. So one, let me Are you changing parameters on the fly?
I'm going to change the code so that they don't do all the things that they're doing. So we can just isolate each one and just show you what it's doing.
So the first thing that they do is they just fly towards the center of mass.
Okay.
So it's just a bunch of different things. They all have a velocity and it says every time period, every tick, every frame, whatever, but it's drifting adjust. And that's because they're not turning immediately. Um, so there and this is this is why I went with this algorithm. There's a lot of different parameters you can tune.
Okay?
So one parameter you can tune is like how quickly does it drift towards that center of mass.
Okay?
And so what you'll see is if we keep this running for a while that ball will just get more and more dense and they'll all just kind of collapse into one point like a singularity. It's it's like okay they're just all attracted to each other. Um but that will eventually collapse onto itself. And so the other the second of the sort of three things that you do in in a void simulation like this is you tell the objects to avoid each other. So instead of just coming in and and eventually collapsing, they if they get too close to something, they'll turn away from because the birds will fall out of the sky.
Yeah. Cuz birds don't want to hit each other.
Oh, okay. So they're like they're attracted but they're kind of like both electrons and they repel just a little bit.
Yeah. So it's so so you've got two rules, right? which is fly towards the center of the flock and then avoid other birds.
Okay.
And that's that gives you this you get this sort of like jumbly cloud.
So that's only two rules.
Yep. That's two rules and you get that.
Okay.
Um and then the third rule is try to match your velocity with the other birds.
And velocity is speed and direction.
Okay.
So this will start to get them to align in in the same direction.
So now they're going to try to match vectors. And now you start to see the flocking behavior.
That is so pleasant.
Dude.
And that's and that that is essentially the Boyd's algorithm. And then there's a few things you can do.
Wait. So So we're seeing three things in there.
You're seeing three things go on.
So they're attracted to each other.
Attracted to each other.
They're trying not to hit each other.
Yep.
And they're trying to match vectors, right?
Wow.
And then you get this flocking behavior that looks looks like birds. It looks like fish. It looks like insects.
It's pretty cool, dude. It's really cool.
And um and so you can do other things.
You can say instead of flying towards the center of the sort of the average position of all the birds, um fly towards the ones that are within some radius of you, which is actually a little bit more realistic because birds don't know where all the other birds are. They just know where the ones near them are, right?
Um and that makes it a lot more interesting because now you get these little groups that break off.
Yeah. Which I I see that often in nature, but that that's a that's a little more broken than I'm used to. So, what parameter are you changing there?
So, I have this visual range parameter.
So, we can crank it up a little bit and they'll form tighter groups. Maybe that was a little too much. They just form one group here. You can see it's starting to feel more like the uh the assembly of a murmmoration. What's interesting is when they pass. Okay.
Yeah, there you go. It took them a while, but they all got together. That feels normal.
That feels more real.
I am in love with this. It's just math.
That's all this is. Each bird is making decisions based on math.
Pick a bird and watch it and watch the decisions it makes.
[Music] [Music] [Laughter] [Music] As they present their bodies to you, they get like really dark. You see that pattern right there? It's really dark.
But as they point towards you, away from you, the aspect angle of their bodies is thinner. So, they look transparent. But then they'll flash in another direction and they get solid looking again as a cloud. There you go. See it? Isn't that awesome? Look at that. Okay. The cool thing about living where I live is I'm up next to Wheeler National Wildlife Refuge and every year thousands of cranes come down here to winter. Today, as I was driving by, I noticed that there were thousands of them and they're all flying in a flock. But I noticed that the flock for these cranes is very different than the small birds. And I think it has to do with the fact that the shape of I'm sorry, they're flying overhead and I got excited. The reason the big birds point in one direction and stay going in one direction is because they're less maneuverable than the small birds. And um that's fascinating to me.
The overall shape of the flock is a function of the maneuverability of would it be the largest bird in the flock? The least maneuverable bird in the flock maybe. Okay, here's a walking trail.
I've done this since I was a little boy.
Um, and it it goes to a hidden observatory so that we can see these birds that have migrated here. Sh, be very quiet. I really like little bridges here.
[Applause] There's a lot of people here today.
It is my understanding that that white one right there is the endangered whooping crane.
So, there's one whooping crane out here.
How do you say it? You say whooping crane.
Whooping crane. Whooping crane. Yeah, whooping crane.
It depends on where you're from.
Depends on where you're from.
One thing I find interesting is as they start walking in one direction, they all try to like walk in the same line. And I wonder if that Boyd's algorithm is kind of working on the ground as well. Like I wonder if they are walking in the same direction in in the same type of pattern that they would fly in. I don't know. It's something to think about. I'm going to go in this store right here and ask them if the birds always are here. I have a feeling they are, but they would know since they work here. How's it going?
Yes, it's fine. How are you?
We were filming the birds.
All right, so this is Andy, and he puts up with the birds. They're here all the time, right?
Yeah.
Every fall and winter.
Every fall and winter. What was your name, man?
Wanda.
Wanda. So mostly during the winter time and uh they stay for a couple months and they they leave in the afternoons about 4:30 till they're gone in the mornings.
So do you like the birds?
They're neat to watch but they're a big nuisance.
I could smell it a little bit out there.
I think that's how they sense really start smelling and right when you start smelling that's when they start coming in.
What is the smell?
They're droppings.
They're urine and and poop.
Yeah.
That's amazing. Well, thanks for letting me uh hang out in your parking lot. I really appreciate it. My name's Destin.
Okay. Yeah. Andy and Wanda. Thank you so much. Going to be good. Good people in Alabama. That's Andy's RV service. Oh, they're going to the ground now. I think they're done. All right, the birds are about to go to sleep, I guess. Go to their little nests or wherever birds go.
I hope you enjoyed this episode. Big thanks to Ben Eater for showing me how all this stuff works. It's pretty cool how powerful a system you can create with just a few simple rules. If you feel like this video earned your subscription, please consider doing that. Maybe hit the bell. If not, no big deal. Thanks to the patrons that support Smarter Every Day. I just want you to look at birds in a new way and think about what each individual bird is doing and what rules dictate the movement of the entire flock. Anyway, I hope you enjoyed this. I'm Destin. You're getting smarter every day. Have a good one. Bye.
[Music]
Up Next

Flocking Simulation with Boids Algorithm in JavaScript and p5.js
@TheCodingTrain
359.3K views•2018-12-11

Building Real-Time ML Pipelines with Feature Stores and MLOps Frameworks
@ODSCAI
5.1K views•2022-02-20

Bypassing Tor Censorship: Bridges and Pluggable Transport Guide
@Coding_ForEveryone
397 views•2024-06-11

Neural Networks Explained: Math, Layers, and Learning Fundamentals
@3blue1brown
21.9M views•2017-10-05
Related Study Plans & Knowledge Roadmaps
Structured learning paths in Artificial Intelligence

![FISIKA VEKTOR KELAS XI [FASE F] PART 1 - KURIKULUM MERDEKA](https://i.ytimg.com/vi/JqB2HI2BwaA/maxresdefault.jpg)




































