[Edu-sig] Brainstorming about January

Kirby Urner urnerk at qwest.net
Mon Dec 13 06:42:20 CET 2004


> As far as I know there are a *lot* of graphics-Toolkits for Python out
> there. Which of them could be used for this task? What are your
> experiences? Do you have significantly faster solutions?
> 

John's graphics.py has a tweak that significantly increases speed, by not
refreshing the screen with each change.

>From his source code:

# Version 2.1 1/15/04
#     Added autoflush option to GraphWin. When True (default) updates on
#        the window are done after each action. This makes some graphics
#        intensive programs sluggish. Turning off autoflush causes updates
#        to happen during idle periods or when flush is called.

Here's a program that takes about 30-50 secs to complete 500,000 loops, but
then almost as long again to actually paint the window.  

The 10,000 loop takes a little over a second.  

I have a 2.8 Ghz P4, gig of RAM.

I find using John's graphics.py (downloadable from his website) is a good
alternative to working directly with Tkinter.  It's a façade, i.e. a wrapper
that simplifies the API.

My thanks to Bernie Gunn for a lot of this:

==========================
# Demo graphic of Sierpinskis Triangle with  Graphics.py

from graphics import *
from random import randint
import time
start = time.time()

# autoflush isn't well documented in Zelle's manual -- mentioned in source
# code comments.  If set to false, window won't update with each new
# draw, meaning we get the 10,000 pixels to plot, THEN show them all
# at once.  Set autoflush to True (default) for pixel-by-pixel rendering
# but in that case, suggest 100 or 1000, vs. 10000 pixels.

win = GraphWin("The Sierpinski Triangle",1280,1024, autoflush = False) #
NOTE autoflush
win.setBackground('white')

shape = Rectangle(Point(10,10), Point(1270,970))
shape.draw(win)
x = 500                    #  = centre of work screen
y = 360
col = 'orange'
man=2

Xd = 200
b2=800
t = Text(Point(Xd,b2), ' .......A Genuine Sierpinski Triangle')
t.setFill("blue")
t.draw(win)

print "Working.... (please be patient)"
                                                
Triang = Polygon(Point(600,20), Point(200,720), Point(1000,720))
Triang.setFill('black')
Triang.draw(win)

i = 1
while i < 500000:  # you can play with this (make it smaller maybe)
    sel = randint(1,3)

    if sel == 1:
        x = (600 + x) / man
        y = (y + 20) / man
    elif sel == 2:
        x = (x + 200) / man
        y = (720 + y) / man
    else:
        x = (1000 + x) / man
        y = (720 + y) / man

    win.plotPixel(x,y,col)
    i += 1

end = time.time()
print end - start

win.getMouse()
win.close()
 
=================

Kirby




More information about the Edu-sig mailing list