 Hey everybody, welcome back to some Python programming. In the last few videos we've been looking at some really cool stuff with some Pygame game stuff we can do working with gravity, working with scrolling platformer kind of setup, working with organizing our code, creating level design, that sort of thing. Right now we're going to take a little bit of a break. I'm going to show you some concepts and some cool things that you can do with the Pygame library that we're going to echo back to our original code with. For now though, actually, if guard. Sorry, I'm talking to myself. For now, let's do a little bit of a quick review how actually we can just build a simple Pygame window, because I mean that's bare basics a long, long time ago. So you can just remind yourself how to create a simple, simple window sub mode. And it's a good idea to create some variables for your window sizes and that sort of thing. I'll just call my width and height and size. I don't really care. I'll make mine pretty small this time so you can actually see it on the screen. It might be a good idea to set yourself up with a background color so you don't have a completely black screen when you run this code. All that. I'm not actually going to update the screen all the time in the event loop just now because I'm actually just going to do this very, very simply with one display and then I'm just going to actually have it run so we can keep watching it and see it happen. Make sure you have your event loop. Had that run all the time with a simple while loop, while running, or while true. It'll run all the time and I don't know why I keep writing Pygame when I'm going to be writing anything else. I'll just let this go. I won't word wrap it like I need to. And then at the end of it all we can just write Pygame.quit. So now if I were to run this, it's just the very, very simple bare bones essential program to get a screen to display. But in this video I wanted to be showing you guys the drawing functions that Pygame has and that Pygame can use. So I have my internet browser open right now and the documentation for Pygame ready and available for us to look at. So you can see we've got Pygame.draw and that's a module for drawing shapes. Honestly this is a super duper awesome module and you'll use it a lot if you are a student. I for one use it a lot because it's a cool and quick and easy way to show people what I mean and stuff like that. And it's helpful for assignments and stuff like that. Whatever. The draw module will draw several simple shapes to a surface. These functions will work for rendering to any format of surface. Running to hardware surfaces will be slower than obviously regular software surface, that sort of thing. Most of the functions as a convention will take a width argument to represent the size of the stroke around the edge of the shape. If the width is zero it'll practically fill the entire shape which is a solid color. All the drawing functions respect the clip area for the surface and will be constrained to that area. The functions are a rectangle representing the boundary area of the chain's pixels. Oh I didn't know that. That's nice. And you can just pass in colors to do this or you can use an alpha quadruplet. It'll be written directly to surface if it contains pixels. The draw function will not draw transparently. Oh the draw function will not draw transparently. I didn't know that either. Man I should look at the documentation more often. Color argument can also be an integer and blah blah blah. Okay what I want to actually get on to right now is drawing functions. So let's skip all of this extra stuff and let's go ahead and draw a rectangle. Notice that this takes in the surface that you're actually drawing it on to. In our case is the window that we just created. You can use any other thing. We had our sprites in the other ones. We had our player and we had our blocks. Those of course have their own image attributes sorry which are services and you can of course draw on those. There are a lot of other services that you can draw on to. Don't think that you are limited to just the plain background of the sublime text. I'm sorry not sublime text but the screen. I don't know what I was thinking there. It takes a rectangle. The function to draw a rectangle will take a rectangle as its arguments. So let's go ahead and create that very very simply. Just to refresh yourself and more so to refresh myself. It takes a width and height and a left top arguments. Let's do rect equals pi game dot rect. And you can have this however you want it to be. You can use left top with height as your arguments or you can use left top and then width and height as your arguments. So however you want to do it I will just use 20 making random noises. 100 and then 200. Okay now let's draw it. Pi game dot draw dot rect just like you saw over here. It takes the surface that we're drawing. It takes the color. Let's actually create a new one. Let's go for red rg. It'll be zero and b will be zero. Window red rect. And let's leave by default with zero. So let's just leave that. Now let's run the program. And you should be able to see we get this fancy thing. I'll set mine to be a 120. 120 height so it's not too huge and it's not off the screen. Then we get this little box. There's our rectangle. Cool. We can of course pass in a width. Just set it to be maybe three. Now remember if it's not zero it won't fill it. It won't fill the entire shape. It'll just draw the outline. It'll be the stroke around the object or the shape. So now that you've seen rect let's change it up a bit. Polygon will take any number of points in a list. Okay I'm not running anymore. My processor or my fan just picked up so I was wondering if I was still running some code because I didn't actually throw a frames per second cap on this so and I should have. Regardless let's look at a point list. Let's get one open. Let's say let's go 2050. It's like we had before. Then let's go zero to five actually. Three is fine whatever. 120 and then let's go let's say 100 90. Also that should be points list. Now we can go ahead and draw. Pygame.draw.polygon and that's going to take the window. It's going to take a color. That's going to take a list of points and that list of points can have any number of points and it will try and figure out a polygon for that. In this case I used three so I tried a I don't know why I wrote color there. That's a stupid thing. Let's go red. In this case I wrote three so it should make a triangle because I'm using three points and you can see there's a triangle. We can make this to be pretty much however we want. We can use 120 and we got another more triangle there. We can draw a right triangle whatever the case may be. I'll actually add a few more points. If I went 120 let's go 150 90. So now I've got more of an irregular shape there and of course you can add more and more of these whatever amount that you want and I'm just using random things right now so you can get an idea of all the funky things that it can do. So there's points list and there's the polygon setup that you can use. I'll put those comments right there. Let's look at another one. Let's look at draw a circle. So this is simple. That uses a position and it uses a radius. Let's use the position width divided by two and height divided by two so it's in the center. And let's go a radius of 30 and we'll fill it in. We don't need the width argument there. Now I've got a red circle. Nice, nice, nice, nice. So that's exactly how that works. You can use 100 if you want and let's use a width of in this case. Go just one so it's really kind of thin. Shrink it down a little bit. Nice. So yeah there's a lot you can do with this. Circles are kind of nice to have ellipses. You can do as well arcs lines. Lines I should show you. Oh you can see some example code to draw just about dangling everything. You can look online for a lot more of these documentation and the references and things that you should know how to do. I'll do line and show you the guys that one. But I mean the point that I'm trying to get across to you is that you can look at all this online and in fact you should because I'm not going to go over all of them. Just things that are helpful to have and use. We have a start position, heading position. Let's go 20 pixels in, 180 down to 350 along to 40 pixels down. And width is by default going to be 1 here but you can of course set that to be whatever you want. Unless that might be 5 so it's a little bit thicker than that. A little bit of a fatter line and you can see that just fine there. So very nice. Those are small things in small drawing functions that you can use and we're actually going to take advantage of these in the next tutorial where we kind of build ourselves a little bit of a very very primitive and mundane world editor. Super duper primitive, super duper lame but it's going to be good for an example and to show you guys what more we can do with this. Right now though those are just the functions. Draw the draw module and library in Pygame is wonderful. I totally recommend you look at this stuff online and play with it a little bit more. It's useful. Okay, that's all that I really meant to show you in this tutorial so I think I'm done and thank you guys for watching. I hope you enjoyed this and I'll see you in the next tutorial. Bye.