-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstopLight.py
More file actions
67 lines (58 loc) · 1.52 KB
/
Copy pathstopLight.py
File metadata and controls
67 lines (58 loc) · 1.52 KB
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
import turtle
turtle.setup(400, 600)
window = turtle.Screen()
window.title("STOP LIGHT EXERCISE")
window.bgcolor("pink")
green = turtle.Turtle()
yellow = turtle.Turtle()
red = turtle.Turtle()
def drawLightFrame ():
green.pensize(3)
green.color('black', 'white')
green.begin_fill()
green.forward(80)
green.left(90)
green.forward(200)
green.circle(40, 180)
green.forward(200)
green.left(90)
green.fillcolor('black')
green.end_fill()
drawLightFrame()
def circle(t, ht, colr):
t.penup()
t.forward(40)
t.left(90)
t.forward(ht)
t.shape('circle')
t.shapesize(3)
t.fillcolor(colr)
circle(red,50, 'green')
circle(yellow, 120, 'yellow')
circle(green, 190, 'red')
state = 0
def stateMachineStopLight():
global state
if state == 0:
green.color('darkgrey')
yellow.color('darkgrey')
red.color('green')
window.ontimer(stateMachineStopLight, 3000)
state = 1
elif state == 1:
green.color('darkgrey')
yellow.color('orange')
window.ontimer(stateMachineStopLight, 1000)
state = 2
elif state == 2:
red.color('darkgrey')
window.ontimer(stateMachineStopLight, 1000)
state = 3
else:
green.color('red')
yellow.color('darkgrey')
window.ontimer(stateMachineStopLight, 2000)
state = 0
stateMachineStopLight()
window.listen()
window.mainloop()