1
import turtle 
turtle.bgcolor("black")
for i in range (15):
    for colours in ("red", "magenta", "blue", "cyan", "green", "yellow"):
        turtle.color(colours)
        turtle.pensize(3)
        turtle.left(4)
        turtle.forward(200)
        turtle.left(90)
        turtle.forward(200)
        turtle.left(90)
        turtle.forward(200)
        turtle.left(90)
        turtle.forward(200)
        turtle.left(90)

I want the speed of the program to run faster than what is running at right now.

enter image description here

ggorlen
  • 44,755
  • 7
  • 76
  • 106
  • 1
    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:06

1 Answers1

0

Folks will answer this by saying use turtle's speed() method, preferably speed('fastest'), or use turtle's tracer(0) and update() methods. (But not both speed() and tracer() as the latter makes the former a no-op.)

But let's think outside the shell and speed this up, faster than speed('fastest')) without using either approach:

from turtle import Screen, Turtle
from itertools import cycle

color = cycle(['red', 'magenta', 'blue', 'cyan', 'green', 'yellow'])

screen = Screen()
screen.bgcolor('black')
screen.register_shape('box', ((0, 0), (20, 0), (20, 20), (0, 20)))

turtle = Turtle(shape='box', visible=False)
turtle.shapesize(10, 10, 3)

def draw():
    turtle.pencolor(next(color))
    turtle.left(4)
    turtle.stamp()

    screen.ontimer(draw)

draw()

screen.mainloop()

Yes, it has its limitations. ;-)

cdlane
  • 40,441
  • 5
  • 32
  • 81