Code

Drawing Polygons in Pygame

The draw.polygon() function allows you to draw a polygon. The function takes in the surface, color, tuple or list of 3 or more xy coordinates for the vertices, and optional width. The width is used to determine line thickness or if the polygon should be filled. When the width is 0, the polygon 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) vertices = [(x1, y1), (x2, y2), (x3, y3)] width = 0 pygame.draw.polygon(displaySurface, displayColor, vertices, width)

0

1

Updated 2021-06-21

Tags

Python Programming Language

Data Science