From: Don S. <saw...@st...> - 2005-07-16 20:42:02
|
Rohit, You might set up your code to run each iteration of your animation separately and asynchronously, such as when a timer event executes. The "flock.py" sample shows an example of this method. I also am new to PythonCard, so if any reader of this message can = correct my advice, please do! Don > -----Original Message----- > From: pyt...@li...=20 > [mailto:pyt...@li...] On=20 > Behalf Of Rohit > Sent: Saturday, July 16, 2005 4:01 AM > To: pyt...@li... > Subject: [Pythoncard-users] Stopping an animation sequence. >=20 > Hi, > I have started using Pythoncard recently, so this may seem=20 > trivial. I was going through the samples which come with it=20 > and I found the "gravity" sample, which animates a number of balls. > I also tried to do something similar to that, but just only=20 > for one ball with one color. For this I used one button to=20 > start the animation, another button to stop it and a canvas=20 > to draw the whole sequence. In the animation sequence the=20 > program keeps on checking whether a flag variable has been=20 > altered to stop the animation or not. > This flag variable was supposed to be altered by the stop=20 > animation button, when a mouse click occured. But when I=20 > click the stop button the animation keeps on running. I am=20 > including the code of my program. >=20 > [code] >=20 > import time,random > from PythonCard import model >=20 > class MyBackground(model.Background): >=20 > def on_initialize(self, event): > self.stopAnimation=3DFalse > pass >=20 > def on_startBtn_mouseClick(self,event): > event.target.enabled=3DFalse > self.stopAnimation=3DFalse > xco=3D50. > yco=3D0. > =20 > xspeed=3Drandom.random()*60-30 > yspeed=3Drandom.random()*60-30 > leftedge=3D0 > rightedge,bottomedge=3Dself.components.canvas.size > topedge=3D0 > gravity=3D2 > drag=3D0.98 > bounce=3D0.5 > radius=3D10 > self.components.canvas.fillColor=3D'red' > prev=3D() > while(not self.stopAnimation): > =20 > self.components.canvas.drawCircle((xco,yco),radius) > time.sleep(0.02) > self.components.canvas.clear(); > self.components.canvas.refresh(); > =20 > xco=3Dxco+xspeed > if(xco+radius>rightedge): > xco=3Drightedge-radius > xspeed=3D-xspeed*bounce > if(xco-radius<leftedge): > xco=3Dleftedge+radius > xspeed=3D-xspeed*bounce > yco=3Dyco+yspeed > if(yco+radius>bottomedge): > yco=3Dbottomedge-radius > yspeed=3D-yspeed*bounce > if(yco-radius<topedge): > yco=3Dtopedge+radius > yspeed=3Dyspeed*bounce > if((int(xco),int(yco))=3D=3Dprev): > break =20 > yspeed=3Dyspeed*drag+gravity > xspeed=3Dxspeed*drag > prev=3D(int(xco),int(yco)) > =20 > def on_stopBtn_mouseClick(self,event): > self.stopAnimation=3DTrue > self.components.startBtn.enabled=3DTrue =20 > =20 > if __name__ =3D=3D '__main__': > app =3D model.Application(MyBackground) > app.MainLoop() >=20 >=20 > [/code] >=20 > Thanks for any help. >=20 > Rohit >=20 >=20 > ------------------------------------------------------- > SF.Net email is sponsored by: Discover Easy Linux Migration=20 > Strategies from IBM. Find simple to follow Roadmaps,=20 > straightforward articles, informative Webcasts and more! Get=20 > everything you need to get up to speed, fast.=20 > http://ads.osdn.com/?ad_idt77&alloc_id=16492&op=3Dick > _______________________________________________ > Pythoncard-users mailing list > Pyt...@li... > https://lists.sourceforge.net/lists/listinfo/pythoncard-users >=20 >=20 |