How to use hide/showturtle to create a stoplight machine in Python?
<p>I have a program that uses the <code>ontimer</code> function to change the colors in a Turtle graphics stoplight from green, to yellow, to red, and back again. Here is the full program of that:</p>

<pre><code>import turtle           

turtle.setup(400,500)
wn = turtle.Screen()
wn.title("Tess becomes a traffic light!")
wn.bgcolor("lightgreen")
tess = turtle.Turtle()


def draw_housing():
""" Draw a nice housing to hold the traffic lights """
   tess.pensize(3)
   tess.color("black", "darkgrey")
   tess.begin_fill()
   tess.forward(80)
   tess.left(90)
   tess.forward(200)
   tess.circle(40, 180)
   tess.forward(200)
   tess.left(90)
   tess.end_fill()


draw_housing()

tess.penup()

tess.forward(40)
tess.left(90)
tess.forward(50)

tess.shape("circle")
tess.shapesize(3)
tess.fillcolor("green")


state_num = 0


def advance_state_machine():
    global state_num
    wn.ontimer(advance_state_machine, 2000)  
    if state_num == 0:       
        tess.forward(70)
        tess.fillcolor("orange")
    state_num = 1
elif state_num == 1:     
    tess.forward(70)
    tess.fillcolor("red")
    state_num = 2
else:                    
    tess.back(140)
    tess.fillcolor("green")
    state_num = 0


advance_state_machine() 
wn.mainloop()
</code></pre>

<p>Now, however, I want to do essentially the same thing, but by using <code>hideturtle</code> and <code>showturtle</code>. I've gotten rid of the <code>advance_state_machine</code> function altogether. In its place is this, beginning right after <code>draw_housing()</code>:</p>

<pre><code>tess.penup()
tess.hideturtle()

green = turtle.Turtle()
green.pu()
green.forward(40)
green.left(90)
green.forward(50)
green.shape("circle")
green.shapesize(3)
green.fillcolor("green")

yellow = turtle.Turtle()
yellow.pu()
yellow.forward(40)
yellow.left(90)
yellow.forward(50)
yellow.shape("circle")
yellow.shapesize(3)
yellow.forward(70)
yellow.fillcolor("orange")

red = turtle.Turtle()
red.pu()
red.forward(40)
red.left(90)
red.forward(190)
red.shape("circle")
red.shapesize(3)
red.fillcolor("red")
</code></pre>

<p>Esentially, I'm trying to create a way to loop hiding and showing each turtle individually to mimic my first program. I could handwrite code to hide and show each turtle on a timer onward to infinity, but I'd rather it continue on its own! Also, is there any easy way to make it so that when one light is "on", the other two are "off", represented as a dimmer/greyed out color, rather than that turtle disappearing completely? Thanks in advance for help/advice.</p>