-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathDrawPolygons.py
63 lines (51 loc) · 2.15 KB
/
DrawPolygons.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import pygame as pg
class DrawPolygons:
def __init__(self):
self.polygon_names = []
self.center_points = []
self.polygon_names.append("square")
self.polygon_names.append("triangle")
self.polygon_names.append("rectangle")
self.center_points.append(Point(100, 100))
self.center_points.append(Point(150, 150))
self.center_points.append(Point(100, 200))
def paint(self, surface: pg.Surface):
white = (255,255,255)
black = (0,0,0)
surface.fill(white)
for i in range(len(self.polygon_names)):
current_polygon = self.polygon_names[i]
current_center = self.center_points[i]
if current_polygon == "square":
pg.draw.rect(surface, black,
pg.Rect(current_center.x-10, current_center.y-10, 20, 20), 2)
elif current_polygon == "triangle":
pg.draw.line(surface, black,
(current_center.x, current_center.y-10),
(current_center.x-10, current_center.y+10), 2)
pg.draw.line(surface, black,
(current_center.x-10, current_center.y+10),
(current_center.x+10, current_center.y+10), 2)
pg.draw.line(surface, black,
(current_center.x+10, current_center.y+10),
(current_center.x, current_center.y-10), 2)
elif current_polygon == "rectangle":
pg.draw.rect(surface, black,
pg.Rect(current_center.x-20, current_center.y-10, 40, 20), 2)
def main():
pg.init()
screen: pg.Surface = pg.display.set_mode([300,300])
polygons: DrawPolygons = DrawPolygons()
polygons.paint(screen)
pg.display.flip()
running = True
while running:
for event in pg.event.get():
if event.type == pg.QUIT:
running = False
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
if __name__ == "__main__":
main()