turtles slowing down

Discussion in 'Python' started by EricC, Jul 19, 2011.

  1. EricC

    EricC Guest

    Hi,

    I am a newbie - I have been teaching myself Python 3 since a few
    months ago. My “self assignments” include some purely for fun. Among
    them was using the turtle module to have multiple turtles running
    around on the screen.

    Recently one such fun turtle “project” showed strange behavior that I
    cannot understand – while I achieved my goals (multiple turtles
    oscillate along random straight lines while changing colors), there
    was a steady slowing down of turtles as time goes. Actually they
    became so slow it is not even fun to look at.

    To trouble shoot the problem by myself, I striped down the codes to
    the minimal that reproduces the problem. In appearance as long as it
    involves “fd()”, it steadily slows down.

    The follows is the striped down version (no multiple turtles, no color
    changes):

    from turtle import *
    import time

    class Ball(Turtle):
    def __init__(self):
    Turtle.__init__(self)
    self.stepsize = 1
    self.steps = 100 # number of steps before turning 180
    deg
    self.counter = 0 # index for counting steps

    def move(self):
    self.fd(self.stepsize)
    if self.counter >= self.steps:
    self.rt(180)
    self.counter = 0
    else:
    self.counter += 1

    def main():
    s = Screen()
    s.clear()
    s.tracer(16, 0)
    b1 = Ball()

    i = 0
    t0 = time.time()
    while True:
    b1.move()
    i += 1
    if i > 2000:
    print(time.time() - t0) # reports time span of the
    interval
    i = 0
    t0 = time.time()

    if __name__ == "__main__":
    main()
    mainloop()

    A sample output to show the lengthening of the interval:

    0.5490000247955322
    0.625999927520752
    0.7360000610351562
    0.8619999885559082
    0.9549999237060547
    1.0649998188018799
    1.2220001220703125
    1.4100000858306885
    1.3619999885559082
    1.56600022315979
    1.942000150680542
    1.816999912261963
    1.8640000820159912
    2.113999843597412
    2.0209999084472656
    2.2710001468658447
    2.254999876022339
    2.3500001430511475
    2.3959999084472656
    2.50600004196167
    2.5850000381469727
    2.7260000705718994
    2.803999900817871
    2.9600000381469727
    3.055000066757202
    3.0859999656677246
    3.2890000343322754
    3.3519999980926514
    3.4609999656677246
    3.6029999256134033
    3.634000062942505
    3.758999824523926
    3.883999824523926
    4.134999990463257
    ....

    Did I do something wrong?

    Thank you very much for your time.

    Best Regards,

    EC
    EricC, Jul 19, 2011
    #1
    1. Advertising

  2. EricC

    Terry Reedy Guest

    On 7/19/2011 6:02 PM, EricC wrote:
    > Hi,
    >
    > I am a newbie - I have been teaching myself Python 3 since a few
    > months ago. My “self assignments” include some purely for fun. Among
    > them was using the turtle module to have multiple turtles running
    > around on the screen.
    >
    > Recently one such fun turtle “project” showed strange behavior thatI
    > cannot understand – while I achieved my goals (multiple turtles
    > oscillate along random straight lines while changing colors), there
    > was a steady slowing down of turtles as time goes. Actually they
    > became so slow it is not even fun to look at.


    There is a bug issue on the tracker that may be related to this.
    Unfortunately, the reviser of the turtle module is not actively
    maintaining it any more, though this might be an underlying tkinter or
    tk issue. Probably something is not being deleted that should be, or you
    are simply overloading the canvas memory and re-compute loop.

    I have not specifically looked at your code.

    --
    Terry Jan Reedy
    Terry Reedy, Jul 20, 2011
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andy Oakey

    ASP.NET application slowing down

    Andy Oakey, Aug 12, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    358
    S. Justin Gengo
    Aug 12, 2003
  2. Bruce Hodge

    Slow Connections Slowing Down Site.

    Bruce Hodge, Nov 16, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    336
    =?Utf-8?B?RURGIFNvZnR3YXJl?=
    Nov 29, 2004
  3. =?Utf-8?B?QmFobWFu?=

    page refresh slowing down

    =?Utf-8?B?QmFobWFu?=, Dec 21, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    359
    bhawin13
    Dec 22, 2005
  4. niles
    Replies:
    10
    Views:
    716
    Mitja
    Jun 22, 2004
  5. Dan Stromberg
    Replies:
    3
    Views:
    262
    Dieter Maurer
    Jun 25, 2006
Loading...

Share This Page