Update of /cvsroot/pythoncard/PythonCard/samples/hopalong
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29328/samples/hopalong
Modified Files:
hopalong.py
Log Message:
minor cleanup and optimization
Index: hopalong.py
===================================================================
RCS file: /cvsroot/pythoncard/PythonCard/samples/hopalong/hopalong.py,v
retrieving revision 1.27
retrieving revision 1.28
diff -C2 -d -r1.27 -r1.28
*** hopalong.py 11 May 2004 11:45:31 -0000 1.27
--- hopalong.py 28 Sep 2004 04:12:11 -0000 1.28
***************
*** 6,12 ****
"""
! from PythonCard import model
import math
- import time
import wx
--- 6,11 ----
"""
! from PythonCard import model, util
import math
import wx
***************
*** 81,92 ****
colorIter = iterations / len(colors)
#print iterations, len(colors), colorIter
!
for i in range(len(colors)):
points = []
for j in range(colorIter):
if x < 0:
! temp = y + math.sqrt(abs(b * x - c))
else:
! temp = y - math.sqrt(abs(b * x - c))
y = a - x
x = temp
--- 80,92 ----
colorIter = iterations / len(colors)
#print iterations, len(colors), colorIter
!
! sqrt = math.sqrt
for i in range(len(colors)):
points = []
for j in range(colorIter):
if x < 0:
! temp = y + sqrt(abs(b * x - c))
else:
! temp = y - sqrt(abs(b * x - c))
y = a - x
x = temp
***************
*** 97,122 ****
def doHopalong(self):
self.statusBar.text = "Drawing, please wait..."
! starttime = time.time()
totalPointsDrawn = 0
! if self.drawing:
! self.components.bufOff.clear()
! for color, points in self.hopalong(float(self.components.fldA.text),
! float(self.components.fldB.text),
! float(self.components.fldC.text),
! int(self.components.fldIterations.text),
! float(self.components.fldXOffset.text),
! float(self.components.fldYOffset.text),
! float(self.components.fldScale.text),
! int(self.components.fldColors.text)):
! if not self.drawing:
! break
! self.components.bufOff.foregroundColor = color
! self.components.bufOff.drawPointList(points)
totalPointsDrawn += len(points)
wx.SafeYield(self)
! stoptime = time.time()
! elapsed = stoptime - starttime
self.statusBar.text = "hopalong time: %f seconds (%d points drawn)" % (elapsed, totalPointsDrawn)
self.drawing = False
--- 97,124 ----
def doHopalong(self):
self.statusBar.text = "Drawing, please wait..."
! canvas = self.components.bufOff
!
! a = float(self.components.fldA.text)
! b = float(self.components.fldB.text)
! c = float(self.components.fldC.text)
! iterations = int(self.components.fldIterations.text)
! xOffset = float(self.components.fldXOffset.text)
! yOffset = float(self.components.fldYOffset.text)
! scale = float(self.components.fldScale.text)
! numColors = int(self.components.fldColors.text)
!
totalPointsDrawn = 0
+ starttime = util.time()
! canvas.clear()
! for color, points in self.hopalong(a, b, c, iterations, xOffset, yOffset, scale, numColors):
! canvas.foregroundColor = color
! canvas.drawPointList(points)
totalPointsDrawn += len(points)
wx.SafeYield(self)
+ if not self.drawing:
+ break
! elapsed = util.time() - starttime
self.statusBar.text = "hopalong time: %f seconds (%d points drawn)" % (elapsed, totalPointsDrawn)
self.drawing = False
***************
*** 125,129 ****
def on_btnDraw_mouseClick(self, event):
! self.drawing = not self.drawing
event.target.enabled = False
self.components.btnCancel.enabled = True
--- 127,131 ----
def on_btnDraw_mouseClick(self, event):
! self.drawing = True
event.target.enabled = False
self.components.btnCancel.enabled = True
|