Home > Software engineering >  How do I make the Turtle drawing speed faster?
How do I make the Turtle drawing speed faster?

Time:09-18

How can I make the Python library Turtle, run and draw a square in 1 screen tick?

import turtle as t
import math

def square():
  t.penup()
  t.goto(cord_x_1, cord_y_1)
  t.pendown()
  t.goto(cord_x_2, cord_y_2)
  t.goto(cord_x_3, cord_y_3)
  t.goto(cord_x_4, cord_y_4)
  t.goto(cord_x_1, cord_y_1)
  t.penup()
 
t.speed(0)
theta = 0

print("What do you want for angle Θ?")
radians_theta = math.fmod(float(theta), 360)
sqrt =  math.sqrt((50)**2 (50)**2)

while 2 > 1: 
  radians_theta = math.fmod(float(theta), 360)

  #cord setup
  cord_x_1 = sqrt * math.cos(radians_theta)
  cord_y_1 = sqrt * math.sin(radians_theta)

  cord_x_2 = sqrt * math.cos(radians_theta   math.radians(90))
  cord_y_2 = sqrt * math.sin(radians_theta   math.radians(90))

  cord_x_3 = sqrt * math.cos(radians_theta   math.radians(180))
  cord_y_3 = sqrt * math.sin(radians_theta   math.radians(180))

  cord_x_4 = sqrt * math.cos(radians_theta   math.radians(270))
  cord_y_4 = sqrt * math.sin(radians_theta   math.radians(270))

  #repeat
  t.clear()
  square()
  theta  = 30
  theta = theta % 360
  print(theta)

What I'm wanting is to have the turtle draw the rotated square very fast. I tried setting the speed to 0, but that is not fast enough. Does anyone know how I could speed turtle up?

CodePudding user response:

Certainly. Sometimes the turtle speed is not fast enough and so there is a way to go even faster. The way would be to disable the animation entirely. t.tracer(0) will disable animation.So put this somewhere near the top of your code. Now at the end of your code you will need t.update() to force an update once the turtle is finished and show it on screen.

  • Related