Aryan Mukhi
Aryan Mukhi

Reputation: 13

Why are my Turtles delaying so much even when I increase their speed?

When the turtle v is drawing the circle, the other turtles move way slower than expected.

I've tried increasing the speed of the turtles, as I thought it might go quicker, but it still stops for 3-4 seconds before moving to a different location:

import turtle
import random

def q():
    x=random.randint(-300,300)
    y = random.randint(-300, 300)
    z = random.randint(-300, 300)
    a = random.randint(-300, 300)



    t.goto (x,y)
    c.goto(a,z)
    t.speed(10000000000000000000000000000000000)
    c.speed(10000000000000000000000000000000000)
    v.color("purple")
    c.color("red")
    v.pensize(width=100)
    v.penup()
    v.setposition(0,-300)
    v.pendown()
    v.circle(350)
t = turtle.Turtle()
c = t.clone()
v = t.clone()
while True:
    q()

Upvotes: 1

Views: 229

Answers (1)

cdlane
cdlane

Reputation: 41905

The problem seems to be that turtle v, which draws the large purple circle, is running at 'normal' speed, not 'fastest' like the other two turtles. Fixing that, and rewriting this as a proper turtle program, speeds it up significantly without the need for tracer():

from turtle import Screen, Turtle
from random import randint

def q():
    x = randint(-300, 300)
    y = randint(-300, 300)
    z = randint(-300, 300)
    a = randint(-300, 300)

    t.goto(x, y)
    c.goto(a, z)

    v.circle(350)

    screen.ontimer(q)  # call again ASAP

screen = Screen()

t = Turtle()
t.speed('fastest')

c = t.clone()
c.color("red")

v = t.clone()
v.color("purple")
v.pensize(width=100)
v.penup()
v.sety(-350)
v.pendown()

q()

screen.mainloop()

Upvotes: 1

Related Questions