Learn Before
Code
Drawing Rectangles in Pygame
The draw.rect() function allows you to draw a rectangle. The function takes in the surface, color, rectangle object, and optional width. The width is used to determine line thickness or if the rectangle should be filled. When the width is 0, the rectangle will be filled. If it's greater than 0, it will determine the thickness of the line. If it's less than 0, nothing will be drawn.
displaySurface = pygame.display.set_mode((1920, 1080)) displayColor = (0, 0, 0) rectangle = (400, 400, 50, 25) #this rectangle is 400 by 400 pixels and drawn on coordinates (50, 25) width = 0 pygame.draw.rect(displaySurface, displayColor, rect, width)
0
1
Updated 2021-06-16
Tags
Python Programming Language
Data Science