From: Kevin A. <ka...@us...> - 2004-05-11 12:06:33
|
Update of /cvsroot/pythoncard/PythonCard/samples/lsystem In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7540/samples/lsystem Modified Files: lsystem.py lsystem.rsrc.py Log Message: added AbstractTurtle optimization removed mouse draw handlers fixed copy and paste for fields added statusBar and time calculation Index: lsystem.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/samples/lsystem/lsystem.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** lsystem.py 9 May 2004 00:50:53 -0000 1.1 --- lsystem.py 11 May 2004 12:06:19 -0000 1.2 *************** *** 7,19 **** from PythonCard import clipboard, dialog, graphic, model ! from PythonCard.turtle import BitmapTurtle import wx import os class LSystem(model.Background): def on_initialize(self, event): - self.x = 0 - self.y = 0 self.filename = None self.on_iterations_select(None) --- 7,18 ---- from PythonCard import clipboard, dialog, graphic, model ! from PythonCard.turtle import AbstractTurtle, BitmapTurtle import wx import os + import time class LSystem(model.Background): def on_initialize(self, event): self.filename = None self.on_iterations_select(None) *************** *** 33,36 **** --- 32,38 ---- def on_Render_command(self, event): + self.statusBar.text = "Drawing, please wait..." + starttime = time.time() + fractalString = self.expand( self.components.scriptField.text, *************** *** 39,43 **** angle = self.components.angle.value self.components.bufOff.autoRefresh = False ! bounds = self.drawFractal( fractalString, 'blue', --- 41,46 ---- angle = self.components.angle.value self.components.bufOff.autoRefresh = False ! ## bounds = self.drawFractal( ! bounds = self.drawAbstractFractal( fractalString, 'blue', *************** *** 58,62 **** --- 61,96 ---- angle, startPos) + + stoptime = time.time() + self.statusBar.text = "Draw time: %.2f seconds" % (stoptime - starttime) + + # KEA 2004-05-08 + # premature optimization <wink> + def drawAbstractFractal(self, aFractalString, color, legLength, angle, startPos): + t = AbstractTurtle(self.components.bufOff.size) + t.lt(90) + t.moveTo(startPos[0], startPos[1]) + bounds = list(startPos + startPos) + for char in aFractalString: + if char=='F': + t.fd(legLength) + x, y = t.getXY() + bounds[0] = min(bounds[0], x) + bounds[1] = min(bounds[1], y) + bounds[2] = max(bounds[2], x) + bounds[3] = max(bounds[3], y) + elif char=='+': + t.rt(angle) + elif char=='-': + t.lt(angle) + elif char=='B': + t.bk(legLength) + elif char=='[': + t.saveState() + elif char==']': + t.restoreState() + return bounds + def drawFractal(self, aFractalString, color, legLength, angle, startPos): self.components.bufOff.clear() *************** *** 65,82 **** t.lt(90) t.moveTo(startPos[0], startPos[1]) ! bounds = list(startPos + startPos) for char in aFractalString: if char=='F': t.fd(legLength) curPos = t.getXY() ! bounds[0] = min(bounds[0], curPos[0]) ! bounds[1] = min(bounds[1], curPos[1]) ! bounds[2] = max(bounds[2], curPos[0]) ! bounds[3] = max(bounds[3], curPos[1]) elif char=='+': t.rt(angle) elif char=='-': t.lt(angle) ! return bounds def expand(self, fractalRules, iterations): --- 99,122 ---- t.lt(90) t.moveTo(startPos[0], startPos[1]) ! ## bounds = list(startPos + startPos) for char in aFractalString: if char=='F': t.fd(legLength) curPos = t.getXY() ! ## bounds[0] = min(bounds[0], curPos[0]) ! ## bounds[1] = min(bounds[1], curPos[1]) ! ## bounds[2] = max(bounds[2], curPos[0]) ! ## bounds[3] = max(bounds[3], curPos[1]) elif char=='+': t.rt(angle) elif char=='-': t.lt(angle) ! elif char=='B': ! t.bk(legLength) ! elif char=='[': ! t.saveState() ! elif char==']': ! t.restoreState() ! ## return bounds def expand(self, fractalRules, iterations): *************** *** 112,128 **** self.panel.Layout() - def on_bufOff_mouseEnter(self, event): - self.x, self.y = event.position - - def on_bufOff_mouseDown(self, event): - self.x, self.y = event.position - event.target.drawLine((self.x, self.y), (self.x + 1, self.y + 1)) - - def on_bufOff_mouseDrag(self, event): - x, y = event.position - event.target.drawLine((self.x, self.y), (x, y)) - self.x = x - self.y = y - def on_btnColor_mouseClick(self, event): result = dialog.colorDialog(self) --- 152,155 ---- *************** *** 164,173 **** def on_menuEditCopy_select(self, event): ! clipboard.setClipboard(self.components.bufOff.getBitmap()) def on_menuEditPaste_select(self, event): ! bmp = clipboard.getClipboard() ! if isinstance(bmp, wx.Bitmap): ! self.components.bufOff.drawBitmap(bmp) def on_editClear_command(self, event): --- 191,208 ---- def on_menuEditCopy_select(self, event): ! widget = self.findFocus() ! if hasattr(widget, 'editable') and widget.canCopy(): ! widget.copy() ! else: ! clipboard.setClipboard(self.components.bufOff.getBitmap()) def on_menuEditPaste_select(self, event): ! widget = self.findFocus() ! if hasattr(widget, 'editable') and widget.canPaste(): ! widget.paste() ! else: ! bmp = clipboard.getClipboard() ! if isinstance(bmp, wx.Bitmap): ! self.components.bufOff.drawBitmap(bmp) def on_editClear_command(self, event): Index: lsystem.rsrc.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/samples/lsystem/lsystem.rsrc.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** lsystem.rsrc.py 10 May 2004 05:02:16 -0000 1.2 --- lsystem.rsrc.py 11 May 2004 12:06:20 -0000 1.3 *************** *** 3,10 **** 'backgrounds': [ {'type':'Background', ! 'name':'bgDoodle', ! 'title':'Doodle PythonCard Application', ! 'position':(603, 190), ! 'size':(579, 529), 'style':['resizeable'], --- 3,11 ---- 'backgrounds': [ {'type':'Background', ! 'name':'bgLSystem', ! 'title':'L-System PythonCard Application', ! 'position':(59, 74), ! 'size':(579, 550), ! 'statusBar':1, 'style':['resizeable'], *************** *** 88,94 **** --- 89,98 ---- 'position':(367, 54), 'size':(200, 20), + 'labels':False, 'layout':'horizontal', 'max':360, 'min':0, + 'tickFrequency':0, + 'ticks':False, 'value':45, }, *************** *** 109,115 **** --- 113,122 ---- 'position':(364, 98), 'size':(200, 20), + 'labels':False, 'layout':'horizontal', 'max':10, 'min':1, + 'tickFrequency':0, + 'ticks':False, 'value':3, }, |