-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStoplight.py
57 lines (48 loc) · 1009 Bytes
/
Stoplight.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
import turtle, time
wn = turtle.Screen()
wn.title("Stoplight")
wn.bgcolor("black")
# Draw box around stoplight
pen = turtle.Turtle()
pen.color("white")
pen.width(3)
pen.hideturtle()
pen.penup()
pen.goto(-30, 60)
pen.pendown()
pen.fd(60)
pen.rt(90)
pen.fd(120)
pen.rt(90)
pen.fd(60)
pen.rt(90)
pen.fd(120)
# Draw red light
red_light = turtle.Turtle()
red_light.shape("circle")
red_light.color("grey")
red_light.penup()
red_light.goto(0, 40)
# Draw yellow light
yellow_light = turtle.Turtle()
yellow_light.shape("circle")
yellow_light.color("grey")
yellow_light.penup()
yellow_light.goto(0, 0)
# Draw green light
green_light = turtle.Turtle()
green_light.shape("circle")
green_light.color("grey")
green_light.penup()
green_light.goto(0, -40)
while True:
yellow_light.color("grey")
red_light.color("red")
time.sleep(4)
red_light.color("grey")
green_light.color("green")
time.sleep(3)
green_light.color("grey")
yellow_light.color("yellow")
time.sleep(2)
wn.mainloop()