Advertisement
phjoe

Meteor

Jan 9th, 2015
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import appuifw as A
  2. import graphics as G
  3. import math
  4. import random
  5.  
  6. class Meteor(object):
  7.  def __init__(self,x,y,z):
  8.   self.p=[0,0,500]
  9.   self.size=8
  10.   self.x=x
  11.   self.y=y
  12.   self.z=z
  13.   self.AX=self.AY=self.AZ=0
  14.  
  15.  def update(self,g):
  16.   cx,cy=W/2,H/2
  17.   sinx=math.sin(self.AX*math.pi/180)
  18.   cosx=math.cos(self.AX*math.pi/180)
  19.   siny=math.sin(self.AY*math.pi/180)
  20.   cosy=math.cos(self.AY*math.pi/180)
  21.   sinz=math.sin(self.AZ*math.pi/180)
  22.   cosz=math.cos(self.AZ*math.pi/180)
  23.  
  24.   ZX=self.x*cosz-self.y*sinz-self.x
  25.   ZY=self.y*sinz + self.y*cosz - self.y
  26.   YX=(self.x+ZX)*cosy - self.z*siny - (self.x+ZX)
  27.   YZ=(self.x+ZX) * siny+self.z * cosy-self.z
  28.   XY=(self.y+ZY)*cosx - (self.z+YZ)*sinx - (self.y+ZY)
  29.   XZ=(self.y+ZY)*sinx + (self.z+YZ)*cosx - (self.z+YZ)
  30.   pp=(self.z+self.p[2]+(XZ+YZ))/dist
  31.   if pp < 0.01:pp=0.01
  32.   dx=(self.x+self.p[0]+(YX+ZX))/pp
  33.   dy=(self.y+self.p[1]+(ZY+XY))/pp
  34.   g.point((cx+dx,cy+dy),0xdfdfff,width=self.size/pp)
  35.   self.p[2]-=2
  36.  
  37. class App:
  38.  def __init__(self):
  39.   self.run=0
  40.   A.app.screen='full'
  41.   self.c = A.Canvas(redraw_callback=self.redraw,event_callback=None)
  42.   A.app.body=self.c
  43.   A.app.menu=[]
  44.   A.app.exit_key_handler = self.stop
  45.  
  46.  def stop(self):
  47.   self.run=0
  48.  
  49.  def redraw(self,x):
  50.   if bg:
  51.    self.c.blit(bg)
  52.  
  53.  def play(self):
  54.   self.run=1
  55.   timer,step=0,20
  56.   while self.run:
  57.    timer+=1
  58.    bg.clear(0)
  59.    if timer>step:
  60.     meteor.append( Meteor(rand(-80,80),rand(-80,80),rand(-40,40)))
  61.     timer=0
  62.    for m in meteor:
  63.     if m.p[2]<0:
  64.      meteor.remove(m)
  65.     m.update(bg)
  66.    self.redraw(0)
  67.    A.e32.ao_sleep(1e-04)
  68.  
  69.  
  70. W,H=G.sysinfo.display_pixels()
  71. bg=G.Image.new((W,H))
  72. dist=200
  73. rand=random.randrange
  74. meteor=[Meteor(rand(-80,80),rand(-80,80),rand(-40,40))]
  75. ap=App()
  76. ap.play()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement