Hi, welcome to this new video. So, we're going to start MOOC three with our first project, project 1, it's going to be a particle system. So we're going to be talking about systems, like how certain many objects interact with each other. And as we discussed initially, all these projects are really going to start putting together the material from the course one and the course two that we developed. So if you haven't really covered that, make sure that you start there, because we really will assume a lot of the principles and knowledge that we covered over those courses already present. So let's talk a little bit about the particle systems. So, a particle system is a technique for creating graphics and creating a simulation, where we can have a large number of small graphical objects, in this case, the particles. We call it a system because there's a series of objects that interact with each other in particular ways. So we have an emitter, that would represent the point from which we are emitting particles. We'll have the particles themselves, which is what we're going to write in this video. And we will eventually introduce forces. The way this project is going to work, we're going to spend the whole week 1 of this course developing this project 1. It's going to take us around eight videos or so to really cover several details and really open different dimensions that allow us to design with these systems and really offer potential for expansion, right? Not only understanding how these elements interact with each other, but also, where would you adapt it and where would you make it yours in different ways? So, as we have these three elements in mind, let's just go deeper into what we're going to write today. We're going to write a particle class. The most central attribute of a particle will be its position, its velocity, and potentially, some other information like lifespan, acceleration. Then some functions, like, does it display itself to the screen, and how it would interact with forces, right? Many software packages have these particles already inbuilt. So you might be wondering, well, why do I need to write my own particle system? Well, we're going to just be learning from a particle system to continue learning python principles. And also, the way in which we would adapt it and not necessarily make it exactly the same, that something that would be featured in a software package, right? So with that in mind, let's just jump into processing and start writing this class. So here we are, we have our template, basically, our setup function. We have imported random, and it's something that we probably will work with canvas size, as we have been doing in the past, and also a background. Let's just open up here and let's create a new tab called particle. Right, and the particle tab, remember that a tab will be a separate file. We're going to also import random here, and let's just write our class particle, right? We're going to define the constructor method for this class With only the position. Position is going to be a vector, right? So if you want to use a variable that specifies more clearly that it's a vector, you could do so. But in general, we're going to be using a lot of vectors for the math and the calculations of positions in space. So we're going to get used to using position as a vector often and velocity and acceleration as vectors. So let's define our self.pos = pos. So at this point, we can just leave it here. What I want to do is just create the simplest form of a particle that we could see in the screen, right? So, we could say def display. So how can we actually draw the particle in the screen? So, stroke(255) fill(0, 0, 255), let's do a blue. Again, here's where you can use your own style. And then the ellipse itself is going to use the position vector, the x coordinate of the position vector, the y coordinate of the position vector. And it's just for now, it could have a variable called size that would define this size here. But I'm going to just hard code a number 5 just because I want to keep this class fairly short, right? So, at this level, this class is actually more of a point if you want, right? A point or kind of ellipse that is just has some location in space, right? To make sure that we have things hooked up correctly, let's go back to our setup and see how we can actually invoke or create instances of this particle. So in our setup, I'm going to create a for loop, right, for i in range(100). And here I could create a new particle. Let's just create a position for the particle. So we're going to create an x = random.randrange(0,1200). That would be the size of our screen. This is a placeholder, but for now let's just create a random position so that we have 100 particles in different random positions, right? Random.randrange(0, 600). So the new particle, the new_particle would be equal to, and here we want to use the particle class. But we don't have access to this at the moment because we haven't really imported the particle class into this script. So let's, do from the file particle, I mean, I named those two files the same, the particle and the class particle. So it might be confusing, but from the file particle, we could say import particle, right? So that means from this file here, which we call particle, import the particle class, right? So now we should have access to this particle class. And let's just come down here, let's create a bit of space. Let's create that particle. And that particle requires a position, right? So we could create the vector here, we could say position and create a vector position, which is equal to pVector(x, y), right? So those two variables create a position vector, and then we pass that vector into the new particle. Because we're working with a collection of particles, we will have to store all these created particles into a list. So let's create an all_particles list, right? So we're using a list data structure to store them. So all_particles.append, this is adding the particle that we created to the list. The new_particle, we're going to add it to the list, right? So at this point, we should have a collection of particles that all have been added to our list. The only final bit here that we need to do would be to define the draw. So where we going to make them appear in the screen. And let's do a background that is black. And for P in, sorry, should be all particles. We're kind of trying to loop through the list of particles for a particle, P in the list of all_particles, p.display, right? So we're basically saying, let's call the function display of that particle every frame, right? So we're looping through those 100 particles we created and we are displaying them, right? So let's see if this is working. I'm having an error, let's see, what are we missing? I think I have a double dot here. Let's see if that's it. Okay, so, we have 100 particles basically created randomly, right? Notice that we don't really have an emitter at this point, the emitter is something kind of invisible, because we are emitting, you could imagine that this for loop is the kind of constructor of particles. So that could be the role of the emitter. And we're not going to focus too much on the emission at the moment, but particles. As we generate it, we could actually give this role of creating the particles to an emission class, or we could give it to some specific characteristics. Like for instance, start from a point or start in a particular direction, right? Or a cone, right? But let's just try to kind of simulate a little bit what particles actually do, which is movement, and the idea of them having some form of behavior of their own, right? So, what we will actually do here, we're not going to offer a new variable for velocity necessarily yet, because we don't need to provide that from outside. So we're going to just say self.velocity, or .vel, for velocity, = PVector. And let's just make all the particles move in a particular direction, right? So something like, towards the right, 1, 0, right? Just a little bit to the right. But for this velocity to take effect, we need to actually do the calculation of updating the particles' position. So, def.update_particle. And here we need our self, right? We would use self.position, so if you think about what we're doing here is, adding the velocity vector, which has some kind of velocity, to the particles position, right? So, self.velocity right? So now we have two functions, I would like to keep the way we invoke those functions rather short. So we're going to create a third function, which is going to be our index or a shortcut for the functions that will simulate our entire system. So we would say, this is going to be calling this function. And this function, right? So, we basically have a run function that calls our two other functions. So now from outside our class, we can only invoke, instead of running the display function, which was rather specific, let's say we're going to run the run function, which contains all the other functions, right? So let's see what we have. We're running into an error. See what we did wrong? So, self.position.add, I was getting ahead of myself here. We need to add the vector. So self.position, add the velocity vector, right? And as we learned in vector math, if we update that position constantly a little bit to the right, we should have our particles moving towards the right, right? So that's pretty straightforward, we've done this independently with circles and other kind of geometry. Let's just create a random vector, so that we actually say x_vel = random vector, I'm going to do a uniform, because I want a value between -1 and 1. And that's a decimal place. So I'm going to say that the initial velocity of all these particles is going to be random, right? And it's going to be the variable for the y. So we have, x velocity is going to be here. So the initial velocity speed, it's going to be done at random, so that we could actually have all these particles moving in random directions, right? We might want to write a function to see how they deal with the environment, what happens when they reach the border, right, things of that sort. For now, this is pretty good, let's just finalize this video. And we have a template or a good starting point for our particles. What would happen if we make them all start from zero? I'm going to comment out this line like this, so that I basically keep a reference. I like doing this when I'm designing with the system. Well, let's start from a particular coordinate, let's just say 600 in the center of the screen, by 300. Or we could start anywhere in the screen. So those are very different starting conditions. And you can see how these particles really started now, from the center, which would be more like an emitter. A point where these particles spread apart and they start simulating their behavior as they go around. So, that's it for this first video, we're going to continue working with this setup. So by all means, just keep this material where we have it here, and we're going to keep building up this particle system in the next following videos. I'll see you then.