<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> delta = []<br> def __init__(self):<br> """Connect to the sensor."""<br> sens = sensor.sensors()['AccSensor']<br> self.s = sensor.Sensor(sens['id'], sens['category'])<br> self.s.connect(self.callme)<br> <br> def callme(self, state):<br> self.delta = []<br> for key in ['data_1', 'data_2', 'data_3']:<br> val = state[key]<br> self.delta.append(int(val + 40)/80)<br><br> def cleanup(self):<br> """Cleanup after yourself. *Must be called* before exiting."""<br> self.s.disconnect()<br><br>sense_conn = SensorConnection()<br><br>appuifw.app.screen='full'<br>img=None<br>def handle_redraw(rect):<br> if img:<br> canvas.blit(img)<br>appuifw.app.body=canvas=appuifw.Canvas(<br> redraw_callback=handle_redraw)<br>img=Image.new(canvas.size)<br><br>running=1<br>def quit():<br> global running<br> 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> img.clear(0)<br> img.blit(text_img, (0,0))<br> img.point((location[0]+blobsize/2,location[1]+blobsize/2),<br> 0x00ff00,width=blobsize)<br> handle_redraw(())<br> e32.ao_yield()<br> e32.reset_inactivity()<br> speed[0]*=friction<br> speed[1]*=friction<br> location[0]+=speed[0]<br> location[1]+=speed[1]<br> <br> n_frames+=1<br> <br> if not sense_conn: continue<br><br> if not len(sense_conn.delta): continue <br> <br> x_bounce_factor = .8 * (1 - min(6,abs(sense_conn.delta[0])) / 9) <br> y_bounce_factor = .8 * (1 - min(6,abs(sense_conn.delta[1])) / 9) <br><br> if location[0]>xs:<br> location[0]=xs-(location[0]-xs)<br> speed[0]= -x_bounce_factor * speed[0]<br> speed[1]=0.90*speed[1]<br> if location[0]<0:<br> location[0]=-location[0]<br> speed[0]= -x_bounce_factor * speed[0]<br> speed[1]=0.90*speed[1]<br> if location[1]>ys:<br> location[1]=ys-(location[1]-ys)<br> speed[0]=0.90*speed[0]<br> speed[1]= -y_bounce_factor * speed[1]<br> if location[1]<0:<br> location[1]=-location[1]<br> speed[0]=0.90*speed[0]<br> speed[1]= -y_bounce_factor * speed[1]<br> <br> speed[0] -= (sense_conn.delta[1]) * acceleration<br> speed[1] -= (sense_conn.delta[0]) * acceleration<br><br> speed[0] = max(min(xs / 2, speed[0]), -xs/2) <br> speed[1] = max(min(ys / 2, speed[1]), -ys/2) <br> <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> n_frames/total,<br> total/n_frames*1000.)<br> <br></div><br><br><br><hr id="stopSpelling">> Date: Thu, 3 Apr 2008 10:34:26 -0400<br>> From: kent37@tds.net<br>> To: thankyouforthevenom1971@hotmail.co.uk<br>> CC: tutor@python.org<br>> Subject: Re: [Tutor] a pyball python app<br>> <br>> dean garrad wrote:<br>> > <br>> > <br>> > this is the part im lil confused about to add the extra ball<br>> > <br>> > location=[img.size[0]/2,img.size[1]/2]<br>> > speed=[0.,0.]<br>> <br>> > i tried copying but it did nothing do i need to copy it and change <br>> > something so the python app dont read the same txt twice and jus do nothing?<br>> <br>> If you want to just copy/paste, you will have to copy all the lines <br>> using location and speed and change the copies to something like <br>> location2 and speed2. Of course you should also change the starting <br>> location or speed so the two balls don't draw in the same place!<br>> <br>> > also on the txt bellow if i add another bal somehow i dotn have to copy <br>> > or change the txt bellow do i? it should create same value for both balls?<br>> <br>> You have to duplicate all the location and speed code, using the new names.<br>> <br>> > also could you link advise any good tuturials that would help me ive <br>> > read some on the net but need more help really.<br>> <br>> The first two tutorials listed here are popular:<br>> http://wiki.python.org/moin/BeginnersGuide/NonProgrammers<br>> <br>> Kent<br>> <br>> PS Please subscribe to the list so I don't have to moderate all your <br>> requests through.<br><br /><hr />Get fish-slapping on Messenger <a href='http://www.fishticuffs.co.uk' target='_new'>Play now!</a></body>
</html>