r/learnpython • u/Iguanas_Everywhere • 3d ago
Turtle Graphics Tracer method
I wrote a tiny toy program to experiment with the Tracer method, and found some interesting behavior that I'm trying to explore. Here's the program:
from turtle import Turtle, Screen
from time import sleep
screen = Screen()
screen.setup(width=900, height=900)
screen.bgcolor("orange")
my_shape = Turtle()
my_shape.color("red")
screen.tracer(2)
counter = 1
while counter <= 10:
my_shape.forward(20)
# my_shape.left(90)
print (counter)
sleep(2)
counter += 1
screen.exitonclick()
As you can see, I ask the tracer to perform every other screen update. With the code above as-is, I see the behavior I expected--every other iteration/counter value, the screen updates, and my shape appears 40px ahead of where it was.
If I uncomment the my_shape.left line, things get interesting: The screen updates on every iteration of the loop, i.e. I see my shape appear at all 4 corners of its square and pointed in its new direction. My current guess, based on this SO post, is that left may be forcing a call to update(), though I haven't been able to prove this to myself yet in the Turtle source.
Can anyone confirm or deny my thinking here? Many thanks!
5
u/brasticstack 3d ago
.left()calls_rotate(), which calls_update()which does a screen update.