-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathshapes.py
More file actions
32 lines (27 loc) · 818 Bytes
/
Copy pathshapes.py
File metadata and controls
32 lines (27 loc) · 818 Bytes
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
import turtle
class Polygon:
def __init__(self, sides, name, size=100, color="black", line_thickness=3):
self.sides = sides
self.name = name
self.size = size
self.color = color
self.line_thickness = line_thickness
self.interior_angles = (self.sides-2)*180
self.angle = self.interior_angles/self.sides
def draw(self):
turtle.color(self.color)
turtle.pensize(self.line_thickness)
for i in range(self.sides):
turtle.forward(self.size)
turtle.right(180-self.angle)
class Square(Polygon):
def __init__(self, size=100, color="black", line_thickness=3):
super().__init__(4, "Square", size, color, line_thickness)
def draw(self):
turtle.begin_fill()
super().draw()
turtle.end_fill()
if __name__ == "__main__":
square = Square(size=300, color="#abcdef")
square.draw()
turtle.done()