Hi, welcome to this new and final video of this week's code regarding the ecosystem. So, in this video, we are going to be calibrating, but also visualizing some of the behaviors within the ecosystem, right? We have our herbivore that has a decision tree. And sometimes debugging or visualizing what is this behavior is actually doing might be incredibly useful to kind of calibrating the system further. And the calibration really talks about the relationships and what is the kind of the way in which we're kind of establishing a relationship between the different classes. The rate of growth, the rate of decay, and the rate of how entries come in or out of the system. Or perhaps calibrating the expression of what are we trying to really achieve. So we're going to be working with this kind of graphic interface that we're going to put on top of our herbivore. It's going to let us see the starvation level, the resting level, the hunger level. So everything that you see in the screen right now is something that we can actually build as a dynamic visualization of the data inside the herbivore's brain. So let's jump into the code and do that. Okay, so we are here in processing. We are continuing working on the code that we have been working for the past several lessons this week. So let's have a quick recap of where we're at. We have the population of herbivores having their own kind of decision tree sequence in seeking food, then resting, then going back to wandering, right? Let's just start visualizing a little bit the information that we have, especially this hunger level, resting level, and starvation level or starvation value. What I would like to do, we do have a function called self display. Let's just create another function here which we haven't constructed yet. But I'm going to call it first self.display_behavior. So our display behavior function, I'm going to write it all the way down at the bottom where our display function is just to have those two together. But I'm going to go down here to display. Let's just create an area here where we can do our display behavior. And I like doing this as a separate function to display, just because eventually I might want to be able to turn this layer on and off. So think of it as like, I might always want to be able to display the entities, the herbivores. But maybe the graphic overlay that shows me the data might be something that I only turn on to kind of visualize its behavior. So what do we want to do? Let's start with the hunger level, right? So let's type here hunger. And we're going to visualize this using a push pop matrix. pushMatrix first, popMatrix to kind of situate a rectangle. We're going to do a rectangle that's going to be (0, 0, 40, or maybe 30, 6) something like that. And let's do fill white, right? So we have a white rectangle, quite small, and we have to position it. So let's translate that rectangle to be in the position of the herbivore self., in the position of the herbivore. Well, that's it, right? In the position of the herbivore. At this point, we should be able to have a wide rectangle. Just place. We're having some error here. Let's see. That should be a coma. Is that it? Okay, so we have the herbivore and we have a rectangle. But you see that this is not really placed in the right location. So in the translate, let's just push it back in x half of the size of the rectangle. So if it's 30 here, we just do a 15 here. And now let's push it in y a little bit up. So an offset, I'm going to do minus, I don't know, 15, maybe -20, right? Let's see what we get. So we have a wide rectangle that's just on top of the herbivore, right? So now we could actually do a second rectangle. Let's call it the background rectangle. The background, the white rectangle is going to have the maximum amount, but we want to include a second rectangle that's going to be a growing bar that's going to be dynamic, that is going to represent the hunger level, right? So let's do that rectangle from (0, 0, with the size in the width of the rectangle would be, let's create a variable called h for hunger and 6 for the height. And that hunger value. It's something we have to construct. We don't have it yet, right? Let's also make it feel the color would be blue, right? So let's do the hunger variable. The hunger variable will be a mapping, right? We know that hunger, it's a value that goes from zero to the maximum hunger threshold, right? Hunger variable will be mapping the variable self.hunger_level, right? So that's the variable. Sorry about this, self.hunger_level that goes from 0 to the hunger threshold, right? That's the range which we know in which that variable moves. And the mapping will allow us to convert this variable to a new range from zero to. In this case, we want it to be between zero and 30 because that's how big the rectangle will be. We want it to be between 0 and 30 somewhere within that domain. So we're kind of converting that variable that has its own domain to a variable that has the domain that we can use graphically. So let's see what we have. And we have now this kind of little growing rectangle because that variable obviously changes over time. When it reaches its max, it transitions to eating food, and we can visualize the behavior of hunger, right? Let's just comment out or create a no stroke call here so we can see it a little bit less. Maybe you do like the kind of the wide rectangle around. I mean, it's a little bit cleaner in my view, right? So there we go. And we can do a function where we repeat these for the different levels, right? But I'm going to manually kind of do it now for rest. So let's just do it for rest. Maybe resting here, we can copy-paste this part of our function. So this exactly the same. Let's just maintain the position in x, the same location. But further up, we're going to put it 30 pixels up. So we have a second bar that is on top of the first one. And this is the resting variable. So we're going to call it r. And you're going to use r here. And instead of saying hunger level, let's just call it rest level. And then also rest. And if you call these variables differently make sure that you use your own name, right? So rest level, rest threshold. And then the color, we might also want to change that to maybe something like red. All right, so this is when the herbivore is taking a nap. After eating, we should be able to see this red bar, which is going to be the second bar filling up. So let's see, for instance, this guy here went to eat. You see the red bar activating, that bars completely transitions back to wandering, right? Which is the time when eventually they will get hungry. So we have resting. And let's do this once more here. We're going to do it for starvation. And this time around, we're going to push the offset of this third bar a little bit further up. It will start getting a bit cluttered, but still. Okay, so in this case, we're going to call a starvation value. I think we call this one differently, right? Starvation value. And here we did call this one starvation threshold, right? And once more, we're going to change the color of this. It's going to be our green. So starvation will be green, was going to be the topmost bar of our creature, right? So let's just look at one of them. When they get hungry, you see, if that green bar builds up and completes, they will start to death and die and disappear out of the system. But one thing I can already can tell that we have a bug, it's not a bug because it's not breaking the system, but it's actually an intended behavior, which is our starvation bar never goes down. So even if you actually eat the food, the creature eats the food, the bar remains high. So there's an inevitable buildup of that bar to the point in which that starvation level will kill the creature. So we're getting creatures not recovering from that starvation state. So let's just fix that. And that's something that really kind of it may be visible for us right now as we kind of created this visualization. So where would we do that? We probably want the starvation value. We can copy-paste that variable. We have to think about this when we eat the food. Let's find the eating food. So here, when we eat the food, the hunger level goes down. But if you ate the food means that you actually got your nutrients back, right? So we could say the starvation value also goes back to o, right? So that you don't have a cumulative starvation. If you keep eating your food in the right time, within your threshold of time, you might still survive, right? So let's see if this is actually doing the change that we intended. So we have some creatures here chasing food, and you see, now they ate the food, starvation went down to zero. So creatures will be more resilient now. But it's only perhaps when there's maybe a competition for resources, when creatures are not going to be able to acquire that food on time. So now that we have all this visualization in place, the final calibration, I try to keep the key parameters for calibration all the way to the top so I don't really have to revisit the functions themselves. The hunger level, the zeros, is not something that we need to work with. But here, this is the threshold of hunger. Do we think that this is how resilient orhow much time the creature would need to wander around before we transitions to a seeking food state? The resting state is the state at the time of the nap. Maybe this nap should be higher. And the starvation threshold, it's like also how much time? I think currently it's pretty brutal, meaning pretty tight on how quickly the animal can actually stay around wandering for food. So again, some parameters that you can actually play around with. We also have this kind of action duration. This is actually, you would have to go into the function because I think we implemented some randomness. So the wonder state kind of transitions between idle, moving, and rotating. And finally, the moving function has different speed of movement for wonder, different speed of movement for the sick food state. So those are the mapping. What are the key parameters that controls the behavior or the expression of the behavior is something to consider. So I'll invite you to kind of really tune those values to something that actually makes sense to you. So we're going to leave this simulation here. I think that we have a new calibration and visualization of these behaviors in a very kind of clear fashion. And we're going to conclude this week discussing where could this ecosystem grow? How could we do more with it because you could imagine that there's a lot more variables and more functions that we can add to it. So we'll have that conversation in the next one. I'll see you then.