Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # joe 10/12/2014
- import appuifw as A
- import graphics as G
- import math
- import random
- rand=random.randint
- run=1
- def stop():
- global run
- run=0
- A.app.screen='full'
- A.app.body=c=A.Canvas()
- A.app.exit_key_handler=stop
- w,h=c.size
- img=G.Image.new((w,h))
- dt,R=1.0,10
- vx=[2,2,2,2]
- vy=[2,2,2,2]
- px=[rand(20,160),rand(20,160),rand(20,160),rand(20,160)]
- py=[rand(20,180),rand(20,180),rand(20,180),rand(20,180)]
- color=[0xff0000,0x00ff00,0x0000ff,0xffff00]
- nxt=1
- while run:
- img.clear(0)
- for i in range(len(px)):
- j=nxt+1
- if (px[i]+dt*vx[i] > w-R) or (px[i]+dt*vx[i] < R):
- vx[i]=-vx[i]
- if (py[i]+dt*vy[i] > h-R) or (py[i]+dt*vy[i] < R):
- vy[i]=-vy[i]
- dx=(px[i]-px[j])+(vx[i]-vx[j])
- dy=(py[i]-py[j])+(vy[i]-vy[j])
- dist=math.sqrt(dx*dx+dy*dy)
- if dist <= (3*R)/2: #2*R
- tempx=vx[i]
- tempy=vy[i]
- vx[i]=vx[j]
- vy[i]=vy[j]
- vx[j]=tempx
- vy[j]=tempy
- px[i]=px[i]+vx[i]*dt
- py[i]=py[i]+vy[i]*dt
- img.ellipse((px[i]-R,py[i]-R,px[i]+R,py[i]+R),fill=color[i])
- c.blit(img)
- A.e32.ao_sleep(0.01)
- A.e32.reset_inactivity()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement