forked from stjohn/csci127
-
Notifications
You must be signed in to change notification settings - Fork 0
/
turtleString.py
36 lines (31 loc) · 1.12 KB
/
turtleString.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
#Modified by: !YourNameHere!
#Email: !YourEmailHere!
#A program that uses command strings to control turtle drawing
import turtle
tess = turtle.Turtle()
myWin = turtle.Screen() #The graphics window
commands = input("Please enter a command string: ")
for ch in commands:
#perform action indicated by the character
if ch == 'F': #move forward
tess.forward(50)
elif ch == 'L': #turn left
tess.left(90)
elif ch == 'R': #turn right
tess.right(90)
elif ch == '^': #lift pen
tess.penup()
elif ch == 'v': #lower pen
tess.pendown()
elif ch == 'B': #go backwards
tess.backward(50)
elif ch == 'r': #turn red
tess.color("red")
elif ch == 'g': #turn green
tess.color("green")
elif ch == 'b': #turn blue
tess.color("blue")
else: #for any other character, print an error message
print("Error: do not know the command:", c)
print("See graphics window for your image")
myWin.exitonclick() #Close the window when clicked