Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 3D Interstellar.py
- import e32,audio,appuifw,os,sys,key_codes,time,math,random,graphics,sensor
- import sysinfo
- xm,ym,zm=(0,0,0)
- xscr=sysinfo.display_pixels()[0]
- yscr=sysinfo.display_pixels()[1]
- ofstars=600
- sz=1
- WHITE=0xffffff
- BLACK=0x000000
- spanse = 700 # 700 should be the minimum
- xv=xscr/2
- yv=yscr/2
- slow = 800
- moveX=range(ofstars)
- moveY=range(ofstars)
- moveZ=range(ofstars)
- XX=range(ofstars)
- YY=range(ofstars)
- ZZ=range(ofstars)
- for i in range(ofstars):
- XX[i]=random.randint(0,spanse)
- YY[i]=random.randint(0,spanse)
- ZZ[i]=random.randint(0,slow)
- def sector():
- global moveX,moveY,moveZ,XX,YY,ZZ
- img.clear(BLACK)
- for i in range(ofstars):
- XX[i]+=int(xm*3.2)
- YY[i]+=int(ym*3.2)
- ZZ[i]+=int(zm*3.2)
- if(XX[i]>spanse):
- XX[i] -= spanse
- elif(XX[i]<0):
- XX[i] += spanse
- if(YY[i]>spanse):
- YY[i] -= spanse
- elif(YY[i]<0):
- YY[i] += spanse
- if(ZZ[i]>slow):
- ZZ[i] -= slow
- XX[i]=random.randint(0,spanse)
- YY[i]=random.randint(0,spanse)
- elif(ZZ[i]<0):
- ZZ[i] += slow
- XX[i]=random.randint(0,spanse)
- YY[i]=random.randint(0,spanse)
- ### start of main 3D effect
- sz=ZZ[i]*0.07
- px=XX[i]+((XX[i]-xv)*(ZZ[i]/100.0))
- py=YY[i]+((YY[i]-yv)*(ZZ[i]/100.0))
- ### line ended of main 3D effect
- img.ellipse([(px,py),(px+sz,py+sz)],WHITE,fill=WHITE)
- img.text((20,40),'X:'+unicode(xm),(WHITE))
- img.text((20,80),'Y:'+unicode(ym),(WHITE))
- canvas.blit(img,(0,0))
- timer.after(0.02,sector)
- draw(img)
- def draw(rect):
- appuifw.e32.reset_inactivity()
- def exit(pos):
- app_lock.signal()
- def redraw():
- global xm,ym,zm
- ym,xm,zm=(sens.x/5,sens.y/5,sens.z/5)
- '''
- ym+=40
- if ym > 25:
- ym = 25
- if ym < -25:
- ym = -25
- '''
- draw(canvas.size)
- '''
- def forLight():
- appuifw.e32.reset_inactivity()
- timer.after(10,forLight)
- timer=appuifw.e32.Ao_timer()
- forLight()
- '''
- img=graphics.Image.new((xscr,yscr))
- appuifw.app.directional_pad=False
- canvas=appuifw.Canvas(redraw_callback=draw)
- appuifw.app.body=canvas
- canvas.bind(key_codes.EButton1Down,exit)
- sens=sensor.AccelerometerXYZAxisData(data_filter=sensor.LowPassFilter())
- sens.set_callback(data_callback=redraw)
- sens.start_listening()
- appuifw.app.screen='full'
- timer=appuifw.e32.Ao_timer()
- appuifw.app.orientation='landscape'
- sector()
- e32.ao_yield()
- app_lock=appuifw.e32.Ao_lock()
- app_lock.wait()
- sens.stop_listening()
- timer.cancel()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement