1

Here's some basic code, how do I make it run faster?

import turtle
wn = turtle.Screen()

sasha = turtle.Turtle()

length = 12
for i in range(65):
    sasha.forward(length)
    sasha.right(120)
    length = length + 10
ggorlen
  • 44,755
  • 7
  • 76
  • 106
apsasha
  • 63
  • 1
  • 9
  • How about `length = length + 11`? – goodvibration Nov 30 '19 at 18:27
  • 3
    Does this answer your question? [Python Turtle Speed](https://stackoverflow.com/questions/37191039/python-turtle-speed) – Uli Sotschok Nov 30 '19 at 18:29
  • @goodvibration, your answer is incorrect because length is used for moving forward. so `length = length + 11` will just add one step forward. It has nothing to do with speed. – DINA TAKLIT Nov 30 '19 at 19:07
  • @aspasha I have answered you question. And I have explained to you how to use the speed function. The link provided by Uli Sotschok is also good. – DINA TAKLIT Nov 30 '19 at 19:09
  • Does this answer your question? [How to speed up python's 'turtle' function and stop it freezing at the end](https://stackoverflow.com/questions/16119991/how-to-speed-up-pythons-turtle-function-and-stop-it-freezing-at-the-end) – ggorlen Dec 05 '22 at 20:07

2 Answers2

3

you can use speed() function The more you increase the more you increase the value the more it is slow.

  • “fastest”: 0
  • “fast”: 10
  • “normal”: 6
  • “slow”: 3
  • “slowest”: 1

You can use it like this sasha.speed(0) for example.

Note: speed(0) is the most fast coz the pen will not draw.

check here for more info

DINA TAKLIT
  • 7,074
  • 10
  • 69
  • 74
2

You can use speed() to change turtle's speed - like in other answer - but you can also turn off animation

 turtle.tracer(False)

and you will have to manually inform turtle when it has to update content on screen

 turtle.update()

This way you can get all at once - without delay

import turtle

turtle.tracer(False) # stop animation and don't update content on screen

wn = turtle.Screen()
sasha = turtle.Turtle()

length = 12
for i in range(65):
    sasha.forward(length)
    sasha.right(120)
    length = length + 10

turtle.update() # update content on screen

turtle.done()

Doc: turtle.tracer(), turtle.update()

furas
  • 134,197
  • 12
  • 106
  • 148