simple fractals with python and Tkinter
Matthew Wilson
mwilson at sarcastic-horse.com
Sun Oct 12 13:57:27 EDT 2003
More information about the Python-list mailing list
Sun Oct 12 13:57:27 EDT 2003
- Previous message (by thread): Uncatchable AttributeError, shelve raises exceptions in __del__
- Next message (by thread): simple fractals with python and Tkinter
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Wow- thanks a lot for the improvements. This feedback is exactly what I was hoping for when I posted the code. I'll study them today. On Sat, 11 Oct 2003 18:46:20 +0200 "Michael Peuser" <mpeuser at web.de> wrote: > > "Matthew Wilson" <mwilson at sarcastic-horse.com> > > > The program is available here: > > > > http://www.sarcastic-horse.com/landscape/pts.py > > > > Hi Matthew, > > Canvas is not very well suited for that kind of visualisation. I often use > the WCK extension (see below for the changes I made waiting for dinner...) > > I encapsulated your drawing code into a routine tkDraw and wrote a > corresponding routine (a class in fact) wckDraw. To speed up things I > included the code for color computation directly. (To generate brushes costs > some time). > > However a *lot* of time is spend inside pt.crect()! > Thus an impressive improvement was realized with: > > import psyco > psyco.full() > > Kindly > MichaelP > > ------- > > #make a sorted list of ticks > ticklist = udict.keys() > ticklist.sort() > > import Tkinter > root = Tkinter.Tk() > root.title('pts') > # eithet tkDraw or wckDraw > wckDraw(root, ptlist, canvaswidth, > canvaswidth,hmin,hmax,ticklist,numticks) > Tkinter.mainloop() > > # old code > def tkDraw(root, ptlist,width,height,hmin,hmax,ticklist,numticks): > > cc = Tkinter.Canvas(root, width=width, height=height, bg="white") > for pt in ptlist: > color = pt.calc_color(hmin, hmax) > rect = pt.crect(ticklist, numticks, width) > cc.create_rectangle(rect, fill=color, outline="") > > cc.pack() > > #new code > from WCK import Widget > class wckDraw(Widget): > def __init__(self, root,ptlist, width, > height,hmin,hmax,ticklist,numticks): > > self.width=width > self.height=height > self.ptlist=ptlist > self.ui_init(root) > self.pack() > colors={} > for pt in ptlist: > if pt.h<=0: > col = int(pt.h/hmin*255) # rgb > else: > col = int(pt.h/hmax*255)*256*256+100*256+100 #rgb > if col not in colors: > colors[col] = self.ui_brush(col) > pt.brush = colors[col] > pt.rect = pt.crect(ticklist, numticks, width) > print "brushes:", len(colors) > def ui_handle_config(self): > print "resize" > return (self.width,self.height) > > def ui_handle_clear(self, draw,x0, y0, x1, y1): > pass > > def ui_handle_repair(self, draw, x0, y0, x1, y1): > for pt in self.ptlist: > draw.rectangle(pt.rect,pt.brush) > > > > > -- > http://mail.python.org/mailman/listinfo/python-list
- Previous message (by thread): Uncatchable AttributeError, shelve raises exceptions in __del__
- Next message (by thread): simple fractals with python and Tkinter
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list