-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdraw.py
More file actions
54 lines (43 loc) · 991 Bytes
/
draw.py
File metadata and controls
54 lines (43 loc) · 991 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
""" exercise 15.2, Allen Downey, _Think Python_ 2nd ed.
"""
import turtle
from mypolygon import polyline, arc
from circle import Circle
from classes import Point, Rectangle
def draw_circle(t, c):
t.pu()
t.goto(c.center.x, c.center.y - c.radius)
t.pd()
arc(t, c.radius, 360)
t.pu()
t.goto(0, 0)
t.seth(0)
def draw_rectangle(t, rect):
t.pu()
t.goto(rect.corner.x, rect.corner.y)
t.pd()
t.seth(0)
for length in rect.width, rect.height, rect.width, rect.height:
t.fd(length)
t.rt(90)
t.pu()
t.goto(0, 0)
t.seth(0)
def main():
c = Circle()
c.center = Point()
c.center.x = 0
c.center.y = 0
c.radius = 100
rect = Rectangle()
rect.corner = Point()
rect.corner.x = -100
rect.corner.y = 100
rect.width = 200
rect.height = 300
bob = turtle.Turtle()
draw_circle(bob, c)
draw_rectangle(bob, rect)
turtle.mainloop()
if __name__ == '__main__':
main()