[New-bugs-announce] Turtle Graphics slowdown

Peter Wentworth p.wentworth at ru.ac.za
Tue Jun 1 18:28:04 CEST 2010


Hi - I observe very erratic (repeatable) slowdown (e.g. 50 times slower
to do some of the sequences of 10 loop iterations) with this
demonstration program. 

The problem only seems to happen when we enable line 46 ...

               tess.dot(None,0,255,0)   

I've added some printing of timings too.

 

This is Python 2.6.5 (r265:79063) on Windows XP.  Is it specifically an
artefact on Windows, or does it also slow down like this on *nix?
Any ideas why?    (I'm not looking for a way to speed it up - I'm
looking for an explanation J)

 

Thanks

Peter

 

---

 

# http://code.activestate.com/recipes/576982/ (r1)

# Levy Dragon Fractal Curve

# FB - 200912093

 

from turtle import *

import time

 

def draw_fractal(length, angle, level, initial_state, target,
replacement, target2, replacement2):

 

    state = initial_state

 

    tess = Turtle()

    tess.hideturtle()

 

    screen = tess.getscreen()

    screen.colormode(255)

    screen.bgcolor("pink")

    screen.delay(0)

    tess.speed(0)

 

    for counter in range(level):

        state2 = ''

        for character in state:

            if character == target:

                state2 += replacement

            elif character == target2:

                state2 += replacement2

            else:

                state2 += character

        state = state2

 

    print(state2)

    # draw

    startTime = time.time()

    moveCount = 0

    for character in state:

        

        moveCount += 1

        if (moveCount % 10 == 0) :

            nowTime = time.time()

            print "Last block of moves took ", nowTime-startTime

            startTime = nowTime

 

        if character == 'F':

            tess.forward(length)

            tess.dot(None,0,255,0)  # If one enables this, things get
bad

        elif character == '+':

            tess.right(angle)

        elif character == '-':

            tess.left(angle)

 

    tess.penup()

    tess.goto(-300,+300)

    tess.write("Click to exit", font=("Comic Sans MS",22, "bold"))

    screen.exitonclick()

 

if __name__ == '__main__':

    draw_fractal(9, 90, 11, 'FX', 'X', 'X+YF+', 'Y', '-FX-Y')

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/new-bugs-announce/attachments/20100601/fa042912/attachment.html>


More information about the New-bugs-announce mailing list