# Flocking Birds – Smarter Every Day 234

published on July 9, 2020

– I don't know why but everydayin that tree right therebirds congregate togetherand then at some point they lift offand they start flying together in a flockYou got all these birds,that are just moving almostlike they're a microorganismYou've got like one individual bird

And it'll be leading the packand then when it turnsthe other ones turnIt's just a fascinating thing,this flock behavior of birdsToday, on Smarter Every DayI wanna talk about thatIt has to do with a mathematical algorithmcalled Boids algorithm

And I've got a computerscientist buddy named Ben Eaterwho's gonna walk us through thatby showing us the mapOh my goodness!(car engine running)You can't see it on film yet'cause of the pixel resolution

But there is a ton over there,and they're all coming to meet right here(laughing)Boom!And we're off,okay they're waiting abouta mile down the road,

Let's go look at 'em(car door opening)We're gonna see if we can see 'em(car engine running)There they are(car engine running)

Try to do this safely here(car engine running)And we'll go to the serviceroad just off of the interstateOh, man!(car engine running)This is what I normally see every day

(soft guitar music)Let's just watch the birdsWhen you're watching 'em,think about it at the bird level,like one individual bird,and think about it from theperspective of the whole flock

It's beautifulAnd you can see like, it'salmost like fluid flowingWhen you can see likeareas of high pressureor high bird density,areas of low bird densityIt's beautiful, I'll quit talking nowlet's just watch birds'cause they're cool

(upbeat music)(upbeat music)(upbeat music)(upbeat music)(upbeat music)(upbeat music)

(upbeat music)Every single bird is making decisionsbased on a very simple set of criteria(upbeat music)So I've watched the birdsin this specific locationfor years and I love it

It's magical every timeBut I've recently learnedthat this is an example ofwhat's called emergent behaviorThe decisions of a single birdwhen thrown in the mixwith the decisions ofa myriad of other birds

Creates this beautiful aerodynamic danceI didn't fully understandhow this works in flocking birdsuntil recently when I was at my friendBen Eater's place out in CaliforniaBen designs and builds his own computers

From the individual electronic components,demonstrating how these simple componentsare combined to makecomplex modern computersBen Eater is an amazing programmerwith a YouTube channel youshould definitely check out- And there is an algorithm

That simulates flocking behavior in birds- Oh really?- Which is called the Boids algorithm,like bird, -oid object- Okay- Or sounds like a New Yorker saying bird

– Okay- So you're about to show—- I thought this- What?I didn't see this- No, you don't see this before

– No- So this is just an implementationof the Boids algorithm- Oh, okay, okay,so it's very difficult,but like I'm tracking some of 'em,and they are kinda gravitationally

Pulled towards the other oneIs that what I'm seeing?- Yeah, so there's actuallythree things going on hereSo let me show you what they are(keyboard typing)

– Is this how actual birds work?- Quite possibly- Really?- YeahSo they're doing a couple of thingsSo one, let me, (keyboard typing)

– Are you changingparameters on the fly?- I'm gonna change the codeso that they don't do all thethings that they're doingSo we can just isolate each one- Okay- So I can just show you what it's doing

So the first thing that they dois they just fly towardsthe center of mass- Okay- So it's just a bunchof different things,they all have a velocityand it says every time period,

Every tick, every frame, whatever- But is drifting- And that's because they'renot turning immediatelyAnd this is why I wentwith this algorithm,there's a lot of differentparameters you can tune- Okay

– So one parameter you can tune is like,how quickly does it drifttowards that center of mass?- Okay- And so what you'll see isif we keep this running for a while,that ball will just getmore and more dense,

And they'll all just kindacollapse into one point- Like a singularityIt's like, okay, got it- They're just allattracted to each otherBut that will eventuallycollapse onto itselfAnd so, the other, the secondof the sort of three things

That you do in a Boidssimulation like this,is you tell the objectsto avoid each otherSo instead of just coming inand eventually collapsing,if they get too close tosomething they'll turn away from- Because the birdswould fall out of the sky- Yeah, 'cause birds don't hit each other

– Oh okay, so they're like,they're attracted, but they'rekind of like both electronsand they repel just a little bit- Yeah, so we've got two rules right,which is fly towardsthe center of the flock,and then avoid other birds

– Okay- And that gives you this,you get this sort of like jumbly clouds- So that's only two rules- Okay- Yep, that's two rulesAnd you get that

– Okay- And then the third rule istry to match your velocitywith the other birdsAnd velocity is speed and direction- Okay- So this will start to get them

To align in the same directionSo now they're gonna try to match vectorsAnd now you sort of see- Oh!the flocking behavior- That is so pleasantDude!

– And that is essentiallythe Boids algorithmAnd then there's a few things you can do- Wait, wait, so we'reseeing three things in there- You're seeing three things going on- So they'reattracted to each other- Attracted to each other

– They're tryingnot to hit each other- Yep- And they'retrying to match vectors- Right- Wow!- And then you get this flocking behavior

That looks like birds,it looks like fish, it looks like insects,it's pretty cool- Dude, it's really cool- And so you can do other things,you can say instead offlying towards the center

Of the, sort of the averageposition of all the birdsfly towards the ones that arewithin some radius of you,which is actually alittle bit more realistic'cause birds don't know whereall the other birds are,they just know wherethe ones near them are- Right

(keyboard typing)- And that makes it a lot more interestingbecause now you get theselittle groups that break off- Yeah, which Isee that often in natureBut that's a little morebroken than I'm used toSo what parameter are you changing there?

– So I have this visual range parameterso we can crank it up a little bit(keyboard typing)And they'll form tighter groups,maybe that was a little too much (laughs)They're just flying in one group

(keyboard typing)There you can see- It's starting to feel more likethe assembly of a murmurationWhat's interesting is when they pass,okay, yeah, there you go,

It took 'em a while,but they all got together- Yeah- That feels normal- Yeah- That feels more real(upbeat music)

(upbeat music)- I am in love with thisIt's just mathThat's all this isEach bird is makingdecisions based on math(upbeat music)

Pick a bird and watch itand watch the decisions it makes(upbeat music)As they present their bodies to you,they get like really darkYou see that pattern right there

It's really darkBut as they pointtowards you away from youthe aspect angle oftheir bodies is thinnerso they look transparentBut then they'll flashin another directionand they get solidlooking again as a cloud

There you go, see it?Isn't that awesome?Look at thatOkay, the cool thing aboutliving where I live is,I'm up next to WheelerNational Wildlife RefugeAnd every year,

Thousands of cranes comedown here to winterToday, as I was driving by,I noticed that there were thousands of 'emand they're all flying in a flockBut I noticed that theflock for these cranesis very different than the small birds

And I think it has to do withthe fact that the shape of,I'm sorry, they're flyingoverhead, and I get excitedThe reason the big birdspoint in one directionand stay going in one directionis because they're lessmaneuverable than the small birdsAnd that's fascinating to me

The overall shape of the flockis a function of the maneuverabilityof what would it be thelargest bird in the flock?The least maneuverable bird in the flock?MaybeOkay, here's a walking trail

I've done this since I was a little boyAnd it goes to a hidden observatoryso that we can see thesebirds that have migrated here(shushing)Be very quietI really like little bridges here

(footsteps)There's a lot of people here todayIt is my understanding thatthat white one right thereis the endangered whooping craneSo there's one whooping crane out hereHow do you say, do you say whooping crane?

– Yup- Whooping crane- Whooping crane?- Yup- Whooping crane- It depends on where you're from(laughing)

– It depends on where you're from?One thing I find interesting isas they start walking in one direction,they all try to likewalk in the same lineAnd I wonder if that Boids algorithmis kind of working on the ground as well

Like I wonder if they arewalking in the same directionin the same type of patternthat they would fly inI don't knowIt's something to think aboutThis episode of Smarter EveryDay is sponsored by KiwiCoThere are several different types of kits

That they send to your houseEverything you need to assemble the kitis included in the boxWe actually went to headquartersWhich one did you get?- (laughing) I got the last one

– (laughing) This is for youThis one's yoursYeah, that's for five plusThat's the Kiwi crateThis is a Tinker crateAnd what, did you get the pinball machine?

– Yes- There's a book, shows them what to doEverything you need is in the boxYou don't have to go tothe store for anythingIf you wanna try thisyou can get it by goingto KiwiCocom/smarter,

Get this sent to your house andyour kids are gonna love itKiwiCo is really good atboosting the kids confidenceAnd that's part of the reasonswhy I reached out to KiwiCo originallyand asked them if they wouldsponsor Smarter Every DayI like it for my kids,

And I think you'll like it for your kids- Dad, how do you do this?- You can do it- It's hard- I know it's hard, butwhen you get done with it,you're gonna be the one that did it

So flip it right down in there- Oh, turn it over- There you go, yeahHow old are you?- Five(Destin laughing)

There's a ton of differentgrades to choose fromwhether you're four or 104there's something that you will enjoySo go check it out at KiwiCocom/smarterGet the first one for freeAnd that's like a \$20 valueor something like that

It's a subscription box soit comes right to your houseand everything's includedGoThat's legit, manYou're gonna dig itWe really like it

– Watch this(playful song)- Oh wow!- It works on everything- I'm gonna go in this store right hereand ask them if the birds always are here

I have a feeling they arebut they would know since they work hereHow's it going?- Yes, nice to see youWe were filming the birdsAlright so this is Andy andhe 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 ma'am?- Wanda

– Wanda?- Mostly during winter timeand they stay for a couplemonths and 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 watchbut they're a big nuisance(Andy laughs)- I could smell it a little bit out there- I think that's how they sense- Really?- When you start smelling that'swhen they start coming in

– What is the smell?- Their droppings- Their urine and poop- Yeah- That's amazingWell, thanks for letting mehang out in your parking lot

I really appreciate itMy name is Destin- Okay- Yeah, Andy and WandaThank you so muchY'all be good

Good people in Alabama,that's Andy's RV serviceThey're going to the ground nowI think they're doneAll right, the birds areabout to go to sleep, I guessGo to their little nestor wherever birds go

I hope you enjoyed this episodeBig thanks to Ben Eater forshowing me how this stuff worksIt's pretty cool, how powerfula system you can createwith just a few simple rulesIf you feel like this videoearned your subscriptionplease consider doingthat maybe hit the bell

If not, no big dealThanks to the patrons thatsupport Smarter Every Day,I just want you to lookat birds in a new wayand think about what eachindividual bird is doing,and what rules dictate themovement of the entire flockAnyway, I hope you enjoyed this

I'm Destin, to getting Smarter Every DayHave a good oneBye(upbeat music))

## Related Videos

hey guys techrax here coming at you guys with another giveaway this is gonna be an iPhone 5s two of these brand new phones not the one in this video guys this i...
hey guy there's a popular game in the app store called flappy bird right now and it's supposedly really annoying believe it or not I haven't played ...
hey guys tech Rex here so right here with me I have an Apple iPhone 5s this is the gold one I also have with me some liquid nitrogen yes this is the real deal a...
hey guys techrax here right here I have the iPhone 5s with me this is the champagne or the gold color I still can't really figure out if it's champagne ...
hey guys tear cracks here so this video really exciting video I have the new Samsung Galaxy s5 for you guys this is the long-awaited cellular devices releases i...
everyone techrax here in this video I've got the latest Samsung Galaxy s5 right here as well as the Apple iPhone 5s and we're going to be doing a simple...
everyone techrax here in this video guys have a really exciting device this is the Samsung Galaxy s5 charcoal black and I'm really liking I after seeing the...
everyone techrax here here with me off the Samsung Galaxy s5 this is a perfectly fine s5 it is cracked from the drop test that I had with also one minor neck as...
hey guys tetrax here so in this video I'm going to try and burn the newly released Samsung Galaxy s5 this is the shimmering white 16 gigabyte model and if y...
everyone techrax here so I got my burn Samsung Galaxy s5 and I wanted to see whether the heartbeat sensor would still work the heart monitor on your galaxy s5 a...
hey guys Tech Rex here so I'm really excited to bring you guys a giveaway for my channel but this time I'm actually teaming up with a buddy of mine your...
hey guys techrax here so in this video I'm going to be hopefully instructing you guys how to make your very own a tech sandwich slash burger slash meal so y...
hey guys techrax here so I've got a galaxy s5 here this is the copper gold hopefully you guys can see pretty well it is sunset so it's getting a little ...
hey guys techrax here so right here with me I have a professional deep fryer in here is already some canola or corn or whatever oil I don't know vegetable o...
hey guys techrax here so just trying to make this video short and quick i'm having recently i got five hundred thousand subscribers and yeah most of you guy...
hey guys texture so in this video I have a drop test on the latest LG g3 device now this is actually the gold-coloured LG g3 this has not been released in the U...
hey guys techrax here so in this video we'll teach you guys how to make your iPhone indestructible this is essentially a case that's been around for yea...
hey guys techrax here soon in this video we had a train run over the iPhone 5s so we actually did this in two different instances initially we had a Space Gray ...
hey guys tech cracks here so in this video we're going to be dropped testing the newly released Amazon fire phone this is exclusive for AT&T and I belie...
hey guys techrax here so right here with me I have the Amazon fire phone this is the one I dropped and you know I thought what better what else do I do with thi...