 from No Start to Press, and I edit textbooks, so today I'm going to talk about flocking, and one of the things that you may think about when you come into this room is what is flocking? So flocking is individuals coming together as a group and moving together. So you'll see flocking in the form of birds literally flocking together, fish schooling, and you may also see flocking in sci-fi movies. So usually alien invaders will come together in a giant flock and will start swarming and attacking. And the thing with movies is usually they're not realistic at all, and that is the case for flocking. So in movie flocking, usually there's one central point of command, and that's really an issue because that's usually what the heroes target in movies when they want to take down the flock and then they win and everything's happy. So there are problems with that, and what goes wrong with that is usually there's one central point that's communicating where individuals should be in the flock. So it's making computations and sending out radio singles, or there might be some queen like in the alien species if they're an insect species that's telepathically telling everyone what to do, all the drones. And when you take down that central command or the queen, then they might just stop moving, the individuals might just drop dead, or something more catastrophic could happen. They just explode in Hollywood fashion. Now this isn't true to life, like birds don't have little antennae coming out of their heads, and fish usually don't have a queen that's communicating to them, and both usually don't explode, hopefully. So a lot of the systems that we think about being centralized really aren't centralized. So for instance, you may think our brain controls our whole entire body, and that's the centralized system, but in actuality our brain's not really micromanaging our individual cells, it's really controlling organs in major systems. So our cells actually have rules and instructions that they follow individually, and then when they come together they work together, and that's the DNA. So this is how flocking kind of works too in real life. The birds will have some rules or instructions that they're following, and then when they come together as a group, interesting behavior emerges, and you start to see patterns, and that's called emergent behavior in biology. So now that I've told you about flocking, I'm going to show you how to actually create a flocking simulation that's really simple. It's really, really simple, and we're going to use NetLogo to do this. And NetLogo is a programming language that's sort of based on logo, and it's agent-based, which means that you have an agent and you tell it what to do. You give it instructions, and these agents are called turtles. So you can see a turtle up here, and that's a little triangle on the screen, and we're going to tell this turtle what to do, and they're going to be a whole bunch of turtles, and we're going to tell each of them individually what they should be doing and give them some rules, and then hopefully we'll make it flock this way. Well, we will, for sure, because... So we're going to do it with three simple rules, which I'll go over in more detail pretty soon, and how we're going to do this is we're going to change one property of the turtles, and that's it, that's all we're going to do. So we're going to just change the turtle's headings, which is the direction that they're facing. So very, very simple. So I'm going to go over some NetLogo code just so you know what's going on. So in this code, we're telling the turtles to... One turtle to look at its neighbors, because we don't want it to look at everyone around it. Like, we don't want it to change its heading for everything, and we're going to tell it to basically draw a radius around itself, and that's vision. Vision is a variable that holds the units of the radius, and then we're going to tell it to look at the other turtles in that radius, because otherwise, if you just tell it to look at all the turtles, it'll look at itself too, and we don't want that. And then we're going to assign that to the constant neighbors using let. So that kind of looks like this, and they have a circle around themselves, that's the vision, the radius field, and the turtle that we're commanding is the red one, and the turtles are the neighbors, are the purple ones. So that's sort of the basic of how this is going to work, and we're going to tell all the turtles in the simulation to do this. So the first rule is to tell the turtles to align together. So we're going to do this by taking all the headings of the neighbors and then averaging them out, and then telling the middle turtle to turn so that it's also facing the same direction. So this is taking all the headings, and then the average is a dotted line, and we're going to tell the turtle, turn. So once we do that, we get all the turtles are traveling together across the screen very slowly, so you'll see that. Yep, so that's cool, right? Okay, next rule is to tell the turtles to stick together. We want them to have some cohesion. It turns out coheses is not a word I found out during this presentation when I was making it. So they're going to cohere together, not coheses. So we're going to get them to do this by checking, do I have any neighbors around me first? And then they're going to draw a smaller circle around themself called minimum cohesion, that's the area that they want other turtles to be in, and my boyfriend called this the lonely zone, because turtles get lonely when no one else is there. So that looks kind of like this. So there are no turtles in the minimum cohesion area, so this turtle is really lonely, and it wants to go near all the other turtles around it. So we're going to do this by taking the average point where its neighbors are. So we just take all the average X coordinates of the neighbors and all the average Y values of the neighbors and average lows. We calculate an average point, so average X and average Y is the average coordinate, and then we need to do some trigonometry. NetLogo is really useful though, so it does some trigonometry magic for us, and we calculate a heading for the turtle from the point it's at to the average point, and then we tell it to turn. So calculate the average point, calculate the heading using the fancy function, and then tell it to a little turn. And when we do that, they start grouping together in the center because that's the average point for all the turtles in the simulation. So that's cool, right? And the last rule is to tell the turtles to separate. Basically, we want them to have a personal bubble. They don't want to run into each other, so we're going to draw another radius around the turtles and tell them that's their personal bubble. If any other turtles are in that personal bubble, any encroachers, then turn away from them because we don't want them to be there. So this is sort of what that looks like. There's a neighboring turtle that's in the personal bubble of that turtle, so it turns away from the turtle that's encroaching in space. And you do that, this kind of looks similar to the alignment you'll see, but the turtles are trying to travel in parallel, so they'll start making an interesting pattern that's kind of similar, but it's important. And when you put all of that together, you get flocking. So the turtles come together in groups and then they merge and they'll separate. And that's what that is. Okay, so this is technically the end of my presentation, but I actually have some more content because I talked fast enough. So extra examples. So this is the same simulation that I just manipulated the variables a bit. And in this, there's no cohesion, so they're not really forming groups. So they're just sort of aligning with each other and then they're trying to stay separated so they're trying to fly in parallel and kind of makes the cool screensaver-ish effect. I thought that was fun. And then in this one, there's a lot of cohesion. They all want to be together, but then they still want to also align and separate. So you'll see like two turtles at a time kind of wiggling out of the group. And then once they reach a certain point, they separate from each other and they go back into the group. So it's cool. And then last example. So here I've added a predator, which is the giant white triangle and it's trying to eat all the turtles on the screen. And you'll see with blocking, they all sort of group together. And theoretically, when this happens, it should make it so that it's harder for the predator to actually get the turtles because they're all trying to fly in the same direction and they're theoretically going to all warn each other kind of like not purposely, but warn each other that there's a predator and to get away. It doesn't work so well in this because we're only changing the headings though. That's something to know. And so if you're interested in flocking and doing something yourself, you can download that logo and they're actually flocking programs in there. They're built in, so it's pretty cool. You can manipulate variables and stuff. And you can also make your own flocking simulations by changing things like speed or the angle in which all the turtles can see because you can make these shapes sort of figurations if the turtles like consider eyesight and stuff, whether they can see a view, they like search stacking. Yeah, and that's it. Thank you very much.