-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathturtle_helper.py
84 lines (74 loc) · 1.64 KB
/
turtle_helper.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import turtle
s = turtle.getscreen()
t = turtle.Turtle() # starts at right:
size = t.turtlesize()
increase = (2 * num for num in size)
t.turtlesize(*increase)
t.pensize(5)
t.shapesize()
t.pencolor("red")
def go_right():
# target = 0
current = t.heading()
if current == 0:
pass
elif current == 90:
t.right(90)
elif current == 180:
t.right(180)
elif current == 270:
t.left(90)
else:
raise ValueError('not a right angle!')
def go_up():
# target = 90
current = t.heading()
if current == 0:
t.left(90)
elif current == 90:
pass
elif current == 180:
t.right(90)
elif current == 270:
t.left(180)
else:
raise ValueError('not a right angle!')
def go_left():
# target = 180
current = t.heading()
if current == 0:
t.left(180)
elif current == 90:
t.left(90)
elif current == 180:
pass
elif current == 270:
t.right(90)
else:
raise ValueError('not a right angle!')
def go_down():
# target = 270
current = t.heading()
if current == 0:
t.right(90)
elif current == 90:
t.right(180)
elif current == 180:
t.left(90)
elif current == 270:
pass
else:
raise ValueError('not a right angle!')
def move_turtle(command):
if command == 'up':
go_up()
elif command == 'down':
go_down()
elif command == 'left':
go_left()
elif command == 'right':
go_right()
elif command == 'go':
t.forward(100)
elif command == 'stop':
print('Stopping the turtle')