forked from AseanK/python-tools-and-games
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathetch_a_sketch.py
61 lines (49 loc) · 1.29 KB
/
etch_a_sketch.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
import turtle
pointer = turtle.Turtle()
screen = turtle.Screen()
colors = ["red", "blue", "green", "yellow", "orange", "black", "purple"]
def intro():
while True:
inp = turtle.textinput(" Etch A Sketch",
""" Welcome!\n
W, A ,S D : Move
Space : Toggle pen
C : Clear
E : Color selection
Enter 'Start' to start!
""").lower()
if inp == 'start':
break
def move_forward():
pointer.fd(10)
def move_backward():
pointer.bk(10)
def tilt_left():
pointer.lt(10)
def tilt_right():
pointer.rt(10)
def on_off():
if pointer.isdown():
pointer.penup()
else:
pointer.pendown()
def clear():
turtle.resetscreen()
def color():
while True:
color = turtle.textinput(" Color Selection",
"Red, Blue, Green, Yellow, Orange, Black, Purple").lower()
if color in colors:
break
pointer.color(color)
turtle.listen()
intro()
turtle.onkeypress(move_forward, "w")
turtle.onkeypress(move_backward, "s")
turtle.onkeypress(tilt_left, "a")
turtle.onkeypress(tilt_right, "d")
turtle.onkey(on_off, "space")
turtle.onkey(clear, "c")
turtle.onkey(color, "e")
turtle.listen()
turtle.mainloop()