From: Kevin A. <ka...@us...> - 2004-09-26 00:10:55
|
Update of /cvsroot/pythoncard/PythonCard/samples/gravity In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5713 Modified Files: gravity.py gravity.rsrc.py Log Message: a little cleanup Index: gravity.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/samples/gravity/gravity.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** gravity.py 25 Sep 2004 21:47:36 -0000 1.3 --- gravity.py 26 Sep 2004 00:10:40 -0000 1.4 *************** *** 11,14 **** --- 11,20 ---- # I started with the doodle sample, so this sample still # contains some cruft + # the big missing item is that I'm not currently doing hit + # detection on the individual balls so they go right through each + # other. I guess that needs to be part of the move method + # with a reference back to the sprites list, but I have + # a feeling it will be more complicated because if ball 1 + # runs into ball 2, then they both need to react... from PythonCard import clipboard, dialog, graphic, model, util *************** *** 18,21 **** --- 24,28 ---- + # helper functions def pointInRect(xy, rect): x, y = xy *************** *** 26,29 **** --- 33,39 ---- return False + def randomColor(): + return (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) + class Sprite(object): *************** *** 92,100 **** self.animate = False self.filename = None - self.color = self.components.btnColor.backgroundColor # leave it black for now #self.components.bufOff.foregroundColor = self.color self.sprites = [] self.initSizers() def initSizers(self): --- 102,111 ---- self.animate = False self.filename = None # leave it black for now #self.components.bufOff.foregroundColor = self.color self.sprites = [] self.initSizers() + # go ahead and create one ball to get started + self.on_btnNewBall_mouseClick(None) def initSizers(self): *************** *** 105,109 **** # Mac wxButton needs 7 pixels on bottom and right macPadding = 7 ! sizer2.Add(comp.btnColor, 0, flags, macPadding) sizer2.Add(comp.btnAnimate, 0, flags, macPadding) sizer2.Add(comp.btnStop, 0, flags, macPadding) --- 116,120 ---- # Mac wxButton needs 7 pixels on bottom and right macPadding = 7 ! sizer2.Add(comp.btnNewBall, 0, flags, macPadding) sizer2.Add(comp.btnAnimate, 0, flags, macPadding) sizer2.Add(comp.btnStop, 0, flags, macPadding) *************** *** 118,127 **** def on_btnAnimate_mouseClick(self, event): event.target.enabled = False canvas = self.components.bufOff canvas.autoRefresh = False - self.sprites.append(BallSprite(self.components.bufOff, 20, 20, 14, self.color)) - # use the last ball added self.animate = True avgfps = 0 --- 129,146 ---- + def on_btnNewBall_mouseClick(self, event): + canvas = self.components.bufOff + self.sprites.append(BallSprite(canvas, 20, 20, 15, randomColor())) + if not self.animate: + canvas.clear() + for ball in self.sprites: + ball.draw() + canvas.redraw() + + def on_btnAnimate_mouseClick(self, event): event.target.enabled = False canvas = self.components.bufOff canvas.autoRefresh = False self.animate = True avgfps = 0 *************** *** 136,140 **** # amount of time that should pass before drawing another frame timePerFrame = 1.0 / fps ! print timePerFrame # hack to force a difference --- 155,159 ---- # amount of time that should pass before drawing another frame timePerFrame = 1.0 / fps ! #print timePerFrame # hack to force a difference *************** *** 155,159 **** canvas.refresh() frame += 1 ! self.statusBar.text = "Average FPS: %f" % (frame / (seconds - startTime)) # give the user a chance to click Stop wx.Yield() --- 174,178 ---- canvas.refresh() frame += 1 ! self.statusBar.text = "Average FPS: %.4f Balls: %d" % (frame / (seconds - startTime), len(self.sprites)) # give the user a chance to click Stop wx.Yield() Index: gravity.rsrc.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/samples/gravity/gravity.rsrc.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** gravity.rsrc.py 25 Sep 2004 20:45:47 -0000 1.1 --- gravity.rsrc.py 26 Sep 2004 00:10:41 -0000 1.2 *************** *** 54,68 **** [ { 'type':'Button', ! 'name':'btnColor', ! 'position':(0, 0), ! 'label':'Color', ! 'backgroundColor':'blue', }, { 'type':'Button', 'name':'btnAnimate', ! 'position':(100, 0), 'label':'Animate' }, { 'type':'Button', 'name':'btnStop', ! 'position':(200, 0), 'label':'Stop' }, { 'type':'BitmapCanvas', --- 54,67 ---- [ { 'type':'Button', ! 'name':'btnNewBall', ! 'position':(5, 5), ! 'label':'New Ball' }, { 'type':'Button', 'name':'btnAnimate', ! 'position':(100, 5), 'label':'Animate' }, { 'type':'Button', 'name':'btnStop', ! 'position':(200, 5), 'label':'Stop' }, { 'type':'BitmapCanvas', |