Re: Turtle graphics speed(). Seems broken

2010-02-27 Thread Alf P. Steinbach

* Dr. Phillip M. Feldman:


Stefan Behnel-3 wrote:

alexander@gmail.com wrote:

I think the speed function may be broken from the turtle graphics package


"from turtle import *

speed('fastest')

forward(50)"


I have tried all of the different speed settings, but I get no change
in the turtle's speed does anyone know how to fix this?

Use "xturtle"? :)

http://ada.rg16.asn-wien.ac.at/~python/xturtle/

Stefan
--
http://mail.python.org/mailman/listinfo/python-list




The Python library's implementation of turtle graphics is slow to the point
that many applications are simply impractical.  I recently converted a
program to Python/turtle graphics that was originally written by my son
using Processing; the result of the conversion is that the time to draw the
balls increased by a factor of roughly 50!  (The Processing version takes
less than 0.1 seconds to generate the image, while the Python version takes
almost 5 seconds on the same computer).  It would be good if this
performance problem can be fixed, either by patching the current
implementation of turtle graphics, or by replacing it with xturtle if that
is better. http://old.nabble.com/file/p27732940/balls.py balls.py 


Try to add

  turtle.tracer( 0 )

before generating the graphics, and

  turtle.update()

after.

It sort of speeds things up. :-)

To test it I had to rewrite your code a little, getting rid of the numpy 
dependency since I don't have numpy installed. Looks like this:




#from numpy import *
def array( data, dtype ): return data   # Emulate numpy array constructor

import random
from math import *
import sys
from time import time
import turtle # turtle graphics module

class Timer:
   """Track and record elapsed time, allowing an arbitrary number of timers."""

   from time import time

   # Constructor:
   def __init__(self):
  self.start= time()

   # Report elapsed time:
   def time(self):

  # Compute elapse time:
  elapsed= time() - self.start

  # Print elapsed time in seconds:
  print str(elapsed) + ' s',

  # If total elapsed time exceeds 60 seconds, also print time as
  # as minutes and seconds:
  if elapsed >= 60.0:
 minutes= numpy.floor(elapsed / 60.0)
 elapsed-= 60 * minutes
 print '= ' + num2str(minutes,0) + ' m ' + num2str(elapsed,3) + ' s'
  else:
 print

def main():


   # Section 1: User inputs.  All four arrays should have the same dimensions.

   balls_of_type = array([20, 20], dtype=int)
   radius_of_type= array([35, 25], dtype=float)
   mass_of_type  = array([4 ,  2], dtype=float)
   color_of_type = array([0 ,  1], dtype=int)

   canvas_width = 1000 # canvas width in pixels
   canvas_height= 800  # canvas height in pixels


   # Section 2: Setup.


   # Section 2.1: Initialize graphics.

   turtle.setup(width=canvas_width, height=canvas_height)

   # Use units of pixels for specifying locations on the screen:
   turtle.setworldcoordinates(0.0, 0.0, canvas_width, canvas_height)

   # Set background color to black:
   turtle.bgcolor("black")

   # We want to specify R, G, and B using whole numbers from 0 to 255:
   turtle.colormode(255)

   # Turn off animation and hide the turtle to get maximum drawing speed:
   turtle.speed('fastest')
   turtle.tracer( 0 )
   turtle.hideturtle()


   # Section 2.2: Preliminaries.

   ball_types= len(balls_of_type)

   max_tries= 1000
   tries= 0

   # The following variable counts the number of time ticks:
   tick= 0

   colors= [
 (255,0,0), # red
 ( 64,   64,  230), # blue, cobalt blue
 (125,0,0), # maroon
 (  0,  255,  255), # cyan,baby blue
 (255,  140,0), # orange
 (  0,  255,0), # green, light green
 (204,  128,0), # brown
 (255,  200,  120), # light orange
 (255,  255,  140), # cream
 (0,128,0), # dark green, forest green
 (255,  128,  128), # peach
 (255,  255,0), # yellow
 (0,  0,  204), # dark blue, navy blue
 (150,  355,  150), # light green
 (128,0,  230), # purple
 (77,   204,0), # avocado
 (255,  128,  255), # magenta, pink
 (0,204,  204), # aqua, turquoise
 (230,  192,0), # gold
 (255,  255,  255), # white
   ]

   # Allocate 2-element lists for basis and velocity vectors:
   u_hat= [0,0]
   v_hat= [0,0]
   uv_speed1b= [0,0]; # before the collision
   uv_speed2b= [0,0]; # before the collision
   uv_speed1a= [0,0]; # after the collision
   uv_speed2a= [0,0]; # after the collision


   # Section 2.3: Calculate the number of balls and allocate arrays whose sizes
   # depend on this.

   # `balls` is the total number of balls:
   balls= sum( balls_of_type )

   x = balls*[0.0]  #zeros(balls, dtype=float)
   y = balls*[0.0]  #zeros(balls, dtype=float)
   x_speed   = balls*[0.0]  #zeros(balls, dtype=float)
   y_speed   = balls*[0.0]  #zeros(balls, dtype=float)

   radius= balls*[0.0]  #zeros(balls, dtype=float)
   mass  = balls*[0.

Re: Turtle graphics speed(). Seems broken

2010-02-27 Thread Dr. Phillip M. Feldman


Stefan Behnel-3 wrote:
> 
> alexander@gmail.com wrote:
>> I think the speed function may be broken from the turtle graphics package
>> 
>> 
>> "from turtle import *
>> 
>> speed('fastest')
>> 
>> forward(50)"
>> 
>> 
>> I have tried all of the different speed settings, but I get no change
>> in the turtle's speed does anyone know how to fix this?
> 
> Use "xturtle"? :)
> 
> http://ada.rg16.asn-wien.ac.at/~python/xturtle/
> 
> Stefan
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 
> 

The Python library's implementation of turtle graphics is slow to the point
that many applications are simply impractical.  I recently converted a
program to Python/turtle graphics that was originally written by my son
using Processing; the result of the conversion is that the time to draw the
balls increased by a factor of roughly 50!  (The Processing version takes
less than 0.1 seconds to generate the image, while the Python version takes
almost 5 seconds on the same computer).  It would be good if this
performance problem can be fixed, either by patching the current
implementation of turtle graphics, or by replacing it with xturtle if that
is better. http://old.nabble.com/file/p27732940/balls.py balls.py 

-- 
View this message in context: 
http://old.nabble.com/Turtle-graphics-speed%28%29.-Seems-broken-tp15504443p27732940.html
Sent from the Python - python-list mailing list archive at Nabble.com.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Turtle graphics speed(). Seems broken

2008-02-15 Thread Stefan Behnel
[EMAIL PROTECTED] wrote:
> I think the speed function may be broken from the turtle graphics
> package
> 
> 
> "from turtle import *
> 
> speed('fastest')
> 
> forward(50)"
> 
> 
> I have tried all of the different speed settings, but I get no change
> in the turtle's speed does anyone know how to fix this?

Use "xturtle"? :)

http://ada.rg16.asn-wien.ac.at/~python/xturtle/

Stefan
-- 
http://mail.python.org/mailman/listinfo/python-list


Turtle graphics speed(). Seems broken

2008-02-15 Thread Alexander . Oot
I think the speed function may be broken from the turtle graphics
package


"from turtle import *

speed('fastest')

forward(50)"


I have tried all of the different speed settings, but I get no change
in the turtle's speed does anyone know how to fix this?
-- 
http://mail.python.org/mailman/listinfo/python-list