Velocity Reviews > turtles slowing down

# turtles slowing down

EricC
Guest
Posts: n/a

 07-19-2011
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

Terry Reedy
Guest
Posts: n/a

 07-20-2011
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

I have not specifically looked at your code.

--
Terry Jan Reedy

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are On Pingbacks are On Refbacks are Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post =?Utf-8?B?QmFobWFu?= ASP .Net 3 12-22-2005 05:24 AM WAState Cisco 12 03-03-2005 06:29 PM Bruce Hodge ASP .Net 1 11-29-2004 03:39 PM niles HTML 10 06-22-2004 07:05 AM Andy Oakey ASP .Net 1 08-12-2003 04:28 PM