Hi, welcome to this new lesson. In this lesson, we are going to learn how actual classes could offer us to create multiple instances of a class. So the whole purpose of really constructing a class is that we can reuse it. That we have code that could be reusable in different instances. But in this specific case is really to kind of start changing the way in which each instance takes different advantage of the data that a class will contain. So let's start where we left off. So, if you remember, this is the code that we left off in the past video. Let's run it. We actually have a class. It's a very kind of maybe redundant description or a very long way of writing a rectangle. But this is the foundation of what a class will be able to, we'll start seeing what a class can actually do for us, right? So we have a class here which is the Gradient_Rectangle. We're calling it a Gradient_Rectangle because we are moving towards the work that we did in the week three that has to do with this kind of gradient vector moving rectangle. But we'll get there. We'll get there soon. First of all, we are defining the class, as you can see here. And then in our setup, we can actually create an instance of this gradient rectangle called gr_01, right? And we are invoking the function display. That, as you can see here, is one of the internal functions of the class. So the first thing I would like to do is to create a second instance of this class. As we explained, we don't have to rewrite the class definition, but we can copy paste this part here. And we can actually just do a number two, right? And this rectangle, let's push it down in y to maybe 110, right? And the size, let's do it slightly smaller. Let's make it of 40 units. And now we have gr_02 here, which is the second instance of this rectangle. And we also can call the display function on that rectangle. So, let's see if this is working. As you can see here, we have two versions of that rectangle. We basically are specifying that these rectangles will have different attributes. And there are two different instances of the same class, right? So as you can see, we didn't have to do any changes to the class whatsoever, but we are able to kind of create two instances of that class. What if we want to include a little bit of different, like, expand the class a little bit more? Let's say we think, well, it would be nice to have some kind of color definition, what if each rectangle also had a specific color? So let's just add an attribute here called color. And we are going to do a self.color = color. So this is going to be a new attribute of the rectangle. And once we use the fill, instead of using the 255,0,0, which is red, we will do a fill, sorry, a self.color, right? So using the color attribute of the class to identify it. Where is this color coming from? It's going to have to be provided in the constructor of the class, right? So right now if we try to run this, we will have an error because we are not providing a color for the class. We need to make sure that we provide the color. So in each one of the constructors of the class, let's add color equals the color, let's do one red as we did it originally. And then in the other case, let's do another one. Green, so 0,255. And we're going to keep the display function once again. So let's try that. I think I'm running into some error here. Yeah, we need a comma here and here. There we go. So as you can see now the rectangles are again instances from the same class, but they're changing attributes. They're changing the attribute of position. They're changing the attribute of size. They're changing the attribute of color, right? Let's add another attribute to this rectangle, and then we'll do a third instance of this class. So one of the things that we started learning in, within our vector session in week three. And again, if you haven't covered that, by all means, just go back a little bit. Week three kind of covers vector math. Let's see how we can create a function called move, right? So this rectangle actually moves over time. So we can do the definition of a function called move. This is written within the class. If you look at the structure of the class, this function move is going to be happening within the class. And we're going to use the self keyword to have access to the internal variables of this class. And here, we can say self.vec_position, which is what we want to change, right? Let's add to that a vector. And we could add a vector, a specific vector, something like a vector of one in x, but we could actually also create a vector. Let's just create one final attribute here that we're going to call the vector velocity. So vector, instead of position, let's use velocity, right? So I know that this is kind of half written. So I need to go back to that. But let's just kind of quickly create a new attribute for this class, which is going to be the self.velocity vector equals vector velocity, right? So now we can actually use this vector velocity, and actually, we need to use self.vector velocity. So the internal velocity of the class. So we're going to use a small arrow, let's say one unit in x. We're going to add that to the position of this rectangle. So we can actually make this rectangle move. So let's try to make them each one of the instances of this class move at a different speed. We need to provide the velocity in the constructor of the class, right? So if we go down here now, you'll see that we have specified color. We need to specify this time a new vector. The vector velocity, it's going to be, let's just copy the way we've been doing vectors in the past. So here, p vector and the velocity, remember that a velocity vector is going to be added every frame, potentially. So we're going to do (1,0). So one in x for the velocity of the red rectangle. And in the case of the green rectangle, let's do a vector velocity of zero, five comma zero. So a bit slower in a way than the previous one. So if we try to run this, we won't see anything. I think we're also missing the comma here, same problem that we had before, there we go. Let's see if that works. We are having an issue. Let's just find our mistake. So let's go back to the script. I kind of found a small error here. I think that this comma here shouldn't be here. This is not the area where we needed to include the comma. When we are here in the, if you remember here in this area, the constructor, these are all lines that could be written as a one line, right. It's a kind of a long series of arguments that are kind of contributing to the constructor of the class. And we certainly need a comma in each one of those cases. But for a moment, I got confused and I added the comma up here. These are just the kind of the variables of the class, so do not include a comma there. So let's see now, in this case, as you can see here, the rectangles are in fact appearing, but they're not moving in any way. That's because we haven't created a draw function yet. There's nothing happening every frame. So let's just create a little bit of space here. Let's do the def draw. And in this area, what we want to do is we want to be able to activate, if you think here, we want to be able to activate the functions of the rectangles, right? We want to display them every frame and we want to move them every frame. But here's where we actually have a little bit of a context problem, right. If we try to execute this within the draw, we'll see that this object is not visible for this context, meaning that it was created within the setup. So let's just go ahead and pick the definition of our gradient rectangle, and let's cut them and let's include them outside the setup. And we are going to bring them back here. So these are kind of just going to be a series of two instances that are going to be visible both for the setup and the draw as we define them prior to those functions, right? So let's just make sure that we can actually execute the function in the draw as well. Let's see if this is working. Okay, so technically, we should be able to now invoke the second function of the, Of the rectangle, which is move, right? So let's do gr_01.move. And the same thing for our second gradient rectangle. And you can see now that that function is being executed, right? So we have both of these classes being drawn with different colors, with different velocities. Now, we're moving away from just a rectangle that maybe we didn't need a class for that. We're actually constructing a series of attributes that belong to that object, right, to that class. And we are realizing that we could also have a series of functions that are unique and internal to that object. So this is what we're starting to do. We're starting to understand how object-oriented programming really works. And how we can actually start expanding the functionality and almost the kind of internal behavior of this object so that we can actually deploy a series of them. Just to conclude this class, I want to just show you we can actually do a third one. And we're going to do the third gradient rectangle. Let's add the position of 170. The size could be of 50 again. Or let's just do a 20. And this one will be slightly faster, right? And the color, let's just add another color here, something like that, right? And now that we actually have this third object, we can actually delete all the display in the setup. Because if we are going to just be displaying it in the draw, I don't think the setup invocation is necessary anymore. And we're going to do this for number 3. And now we have three rectangles. The third one is slightly faster than the first one, but it's smaller, right? So we're starting to see all these different rectangles moving towards the right of the screen, right? But as you can probably identify, the process gets quite tedious if we actually have to copy paste the creation of instances of classes, right? All this process is something that we can automate or potentially construct within a loop structure. So that's what we're going to do in the next session. We're going to see how to move away from an explicit construction of a class, but we could actually do them within a for loop or within kind of a looping structure, right? So I'll see you in the next session.