<html>
<head>
<style>
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
FONT-SIZE: 10pt;
FONT-FAMILY:Tahoma
}
</style>
</head>
<body class='hmmessage'><div style="text-align: left;">hi i signed onto the site it asked me to. :).<br><br><br>can i talk to ya now more ? <br><br>im not sure if i am in wrong place to send e mail to you still<br><br><br>i still ahving problems with the ball script this is the script at the moment how it stands with 1 ball working fine and i have been trying to add another ball to the script.<br><br>i coppied the txt and added a location2 aswell as location. but it didnt seam to work :S <br><br><br>import appuifw<br>from graphics import *<br>import e32<br><br>import sensor<br>class SensorConnection(object):<br>&nbsp;&nbsp;&nbsp; delta = []<br>&nbsp;&nbsp;&nbsp; def __init__(self):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; """Connect to the sensor."""<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sens = sensor.sensors()['AccSensor']<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.s = sensor.Sensor(sens['id'], sens['category'])<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.s.connect(self.callme)<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; def callme(self, state):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.delta = []<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for key in ['data_1', 'data_2', 'data_3']:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; val = state[key]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.delta.append(int(val + 40)/80)<br><br>&nbsp;&nbsp;&nbsp; def cleanup(self):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; """Cleanup after yourself. *Must be called* before exiting."""<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.s.disconnect()<br><br>sense_conn = SensorConnection()<br><br>appuifw.app.screen='full'<br>img=None<br>def handle_redraw(rect):<br>&nbsp;&nbsp;&nbsp; if img:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; canvas.blit(img)<br>appuifw.app.body=canvas=appuifw.Canvas(<br>&nbsp;&nbsp;&nbsp; redraw_callback=handle_redraw)<br>img=Image.new(canvas.size)<br><br>running=1<br>def quit():<br>&nbsp;&nbsp;&nbsp; global running<br>&nbsp;&nbsp;&nbsp; running=0<br><br>appuifw.app.exit_key_handler=quit<br><br>location=[img.size[0]/2,img.size[1]/2]<br>speed=[0.,0.]<br>blobsize=16<br>xs,ys=img.size[0]-blobsize,img.size[1]-blobsize<br>acceleration=0.05<br>friction = 0.993<br><br>import time<br>start_time=time.clock()<br>n_frames=0<br><br># To speed things up, we prerender the text.<br>labeltext=u'Tilt the phone to move'<br>textrect=img.measure_text(labeltext, font='normal')[0]<br>text_img=Image.new((textrect[2]-textrect[0],textrect[3]-textrect[1]))<br>text_img.clear(0)<br>text_img.text((-textrect[0],-textrect[1]),labeltext,fill=0xffffff,font='normal')<br><br>while running:<br>&nbsp;&nbsp;&nbsp; img.clear(0)<br>&nbsp;&nbsp;&nbsp; img.blit(text_img, (0,0))<br>&nbsp;&nbsp;&nbsp; img.point((location[0]+blobsize/2,location[1]+blobsize/2),<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0x00ff00,width=blobsize)<br>&nbsp;&nbsp;&nbsp; handle_redraw(())<br>&nbsp;&nbsp;&nbsp; e32.ao_yield()<br>&nbsp;&nbsp;&nbsp; e32.reset_inactivity()<br>&nbsp;&nbsp;&nbsp; speed[0]*=friction<br>&nbsp;&nbsp;&nbsp; speed[1]*=friction<br>&nbsp;&nbsp;&nbsp; location[0]+=speed[0]<br>&nbsp;&nbsp;&nbsp; location[1]+=speed[1]<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; n_frames+=1<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; if not sense_conn: continue<br><br>&nbsp;&nbsp;&nbsp; if not len(sense_conn.delta): continue&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; x_bounce_factor = .8 * (1 - min(6,abs(sense_conn.delta[0])) / 9) <br>&nbsp;&nbsp;&nbsp; y_bounce_factor = .8 * (1 - min(6,abs(sense_conn.delta[1])) / 9) <br><br>&nbsp;&nbsp;&nbsp; if location[0]&gt;xs:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; location[0]=xs-(location[0]-xs)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; speed[0]= -x_bounce_factor * speed[0]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; speed[1]=0.90*speed[1]<br>&nbsp;&nbsp;&nbsp; if location[0]&lt;0:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; location[0]=-location[0]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; speed[0]= -x_bounce_factor * speed[0]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; speed[1]=0.90*speed[1]<br>&nbsp;&nbsp;&nbsp; if location[1]&gt;ys:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; location[1]=ys-(location[1]-ys)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; speed[0]=0.90*speed[0]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; speed[1]= -y_bounce_factor * speed[1]<br>&nbsp;&nbsp;&nbsp; if location[1]&lt;0:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; location[1]=-location[1]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; speed[0]=0.90*speed[0]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; speed[1]= -y_bounce_factor * speed[1]<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; speed[0] -= (sense_conn.delta[1]) * acceleration<br>&nbsp;&nbsp;&nbsp; speed[1] -= (sense_conn.delta[0]) * acceleration<br><br>&nbsp;&nbsp;&nbsp; speed[0] = max(min(xs / 2, speed[0]), -xs/2) <br>&nbsp;&nbsp;&nbsp; speed[1] = max(min(ys / 2, speed[1]), -ys/2) <br>&nbsp;&nbsp;&nbsp; <br>end_time=time.clock()<br>total=end_time-start_time<br><br>sense_conn.cleanup()<br><br>print "%d frames, %f seconds, %f FPS, %f ms/frame."%(n_frames,total,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; n_frames/total,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; total/n_frames*1000.)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br></div><br><br><br><hr id="stopSpelling">&gt; Date: Thu, 3 Apr 2008 10:34:26 -0400<br>&gt; From: kent37@tds.net<br>&gt; To: thankyouforthevenom1971@hotmail.co.uk<br>&gt; CC: tutor@python.org<br>&gt; Subject: Re: [Tutor] a pyball python app<br>&gt; <br>&gt; dean garrad wrote:<br>&gt; &gt; <br>&gt; &gt; <br>&gt; &gt; this is the part im lil confused about to add the extra ball<br>&gt; &gt; <br>&gt; &gt; location=[img.size[0]/2,img.size[1]/2]<br>&gt; &gt; speed=[0.,0.]<br>&gt; <br>&gt; &gt; i tried copying but it did nothing do i need to copy it and change <br>&gt; &gt; something so the python app dont read the same txt twice and jus do nothing?<br>&gt; <br>&gt; If you want to just copy/paste, you will have to copy all the lines <br>&gt; using location and speed and change the copies to something like <br>&gt; location2 and speed2. Of course you should also change the starting <br>&gt; location or speed so the two balls don't draw in the same place!<br>&gt; <br>&gt; &gt; also on the txt bellow if i add another bal somehow i dotn have to copy <br>&gt; &gt; or change the txt bellow do i? it should create same value for both balls?<br>&gt; <br>&gt; You have to duplicate all the location and speed code, using the new names.<br>&gt; <br>&gt; &gt; also could you link advise any good tuturials that would help me ive <br>&gt; &gt; read some on the net but need more help really.<br>&gt; <br>&gt; The first two tutorials listed here are popular:<br>&gt; http://wiki.python.org/moin/BeginnersGuide/NonProgrammers<br>&gt; <br>&gt; Kent<br>&gt; <br>&gt; PS Please subscribe to the list so I don't have to moderate all your <br>&gt; requests through.<br><br /><hr />Get fish-slapping on Messenger <a href='http://www.fishticuffs.co.uk' target='_new'>Play now!</a></body>
</html>