Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import appuifw as A
- import graphics as G
- import math
- import random
- class Meteor(object):
- def __init__(self,x,y,z):
- self.p=[0,0,500]
- self.size=8
- self.x=x
- self.y=y
- self.z=z
- self.AX=self.AY=self.AZ=0
- def update(self,g):
- cx,cy=W/2,H/2
- sinx=math.sin(self.AX*math.pi/180)
- cosx=math.cos(self.AX*math.pi/180)
- siny=math.sin(self.AY*math.pi/180)
- cosy=math.cos(self.AY*math.pi/180)
- sinz=math.sin(self.AZ*math.pi/180)
- cosz=math.cos(self.AZ*math.pi/180)
- ZX=self.x*cosz-self.y*sinz-self.x
- ZY=self.y*sinz + self.y*cosz - self.y
- YX=(self.x+ZX)*cosy - self.z*siny - (self.x+ZX)
- YZ=(self.x+ZX) * siny+self.z * cosy-self.z
- XY=(self.y+ZY)*cosx - (self.z+YZ)*sinx - (self.y+ZY)
- XZ=(self.y+ZY)*sinx + (self.z+YZ)*cosx - (self.z+YZ)
- pp=(self.z+self.p[2]+(XZ+YZ))/dist
- if pp < 0.01:pp=0.01
- dx=(self.x+self.p[0]+(YX+ZX))/pp
- dy=(self.y+self.p[1]+(ZY+XY))/pp
- g.point((cx+dx,cy+dy),0xdfdfff,width=self.size/pp)
- self.p[2]-=2
- class App:
- def __init__(self):
- self.run=0
- A.app.screen='full'
- self.c = A.Canvas(redraw_callback=self.redraw,event_callback=None)
- A.app.body=self.c
- A.app.menu=[]
- A.app.exit_key_handler = self.stop
- def stop(self):
- self.run=0
- def redraw(self,x):
- if bg:
- self.c.blit(bg)
- def play(self):
- self.run=1
- timer,step=0,20
- while self.run:
- timer+=1
- bg.clear(0)
- if timer>step:
- meteor.append( Meteor(rand(-80,80),rand(-80,80),rand(-40,40)))
- timer=0
- for m in meteor:
- if m.p[2]<0:
- meteor.remove(m)
- m.update(bg)
- self.redraw(0)
- A.e32.ao_sleep(1e-04)
- W,H=G.sysinfo.display_pixels()
- bg=G.Image.new((W,H))
- dist=200
- rand=random.randrange
- meteor=[Meteor(rand(-80,80),rand(-80,80),rand(-40,40))]
- ap=App()
- ap.play()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement