Draw Shapes in Pygame By albro

Today I'm looking to work with simple shapes in the Pygame. Before starting the game, I want to talk about drawing simple shapes such as line, circle, oval, square or rectangle, etc.
Draw a Line
The first shape to talk about is the line. Perhaps this is the simplest form! To draw a line we need two points. We start from one point and extend to the next. In Pygame, we need these two points to draw a line.
Let's take a look at the line drawing function in Pygame:

This function has 5 parameters. First of all, we need to determine where the line should be drawn. Our line must definitely be drawn on the screen or display object. So the first parameter is the display level. In the second parameter, we must specify the color of the line. As I said, I need two points to draw a line. The starting point and the ending point. The third and fourth parameters specify the starting and ending points of the line, respectively.
But as I said before, the screen is 2D, so to determine each point, we must determine two numbers for the X and Y coordinates. For this reason, the start and end point must be given to the function in the form of two tuples!
The last parameter is used to determine the line width. For example, we have:
pygame.draw.line(SCREEN, GREEN, (50,100),(150,200),6)
In the code above, we draw a line, the beginning of which is a point with coordinates (50,100) and the end of which is a point with coordinates (150,200). The last parameter used for width is 6 pixels. Note that the existence of the last parameter is optional and can be omitted!

Draw a Rectangle
The second shape that I want to draw is a rectangle. The function required to draw this shape is as follows:

A maximum of 4 parameters are needed to draw a rectangle. The first and second parameters are the same as the previous display object and rectangle color. In the third parameter, we must specify 4 numbers. For this we use two tuples. The first tuple is used to determine the starting point of drawing a rectangle. This point is the coordinate of the upper left corner. In the second tuple, two numbers specify the width and height of the rectangle, respectively.
Finally, the fourth parameter determines the amount of border and the hollow of the rectangle. If this number is specified, the rectangle will be hollow.

Pay attention to the following figure:
![Rectangle With[out] Border](https://files.peakd.com/file/peakd-hive/albro/23xVm3jsAyg6UqYsdC8oMKgbhRpBu7C7G4EtWFP1tWAeZXXHQkXJ853v6AqoebyxwKA7v.png)
Draw a Circle
Do you remember what we used to do to draw a circle in math? We would take the compass and open it to the desired size. Then we would place at the desired point, which would be the center of the circle, and we would draw a circle with. The same is true here.
To draw a circle we need two things. A point as the center of the circle and a radius!
To draw a circle, we need the following function:

This function has a maximum of 5 parameters. The first two are the same as before. The third parameter specifies the center of the circle. I write it as a tuple to determine the X and Y coordinates. The fourth parameter is the size of the radius of the circle. Finally, the last parameter specifies the value of the border. If the last parameter is missing, we will have a solid circle with the specified color.
![Circle With[out] Border](https://files.peakd.com/file/peakd-hive/albro/EoH5cfDgRGcVCRxR9mpswFggpEroCsem1tdZ48swDPr9dKY7bYbZBPmkd1ifygfqTwK.png)
Draw aaline


Draw Ellipse

To draw an ellipse, we need its center and the size of two diameters. Therefore, the first two parameters are the same as before. The third parameter is also a quadruple tuple where the first two numbers are the coordinates of the center of the circle and the next two numbers specify the size of the horizontal and vertical diameters of the ellipse. The last parameter also determines the value of the border, as in the previous cases.

Draw Polygon

The only difference of the above function is in its third parameter. In the third parameter, we must give a list of points to the function. This function connects the points one by one and finally connects the two starting and ending points to create a polygon.
pygame.draw.polygon(screen, RED, ((100,300), (100,200), (150,150), (200,200), (200,300)), 1)











Comments