Advertisement
here2share

# 3D Interstellar.py

Nov 29th, 2014
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # 3D Interstellar.py
  2.  
  3. import e32,audio,appuifw,os,sys,key_codes,time,math,random,graphics,sensor
  4. import sysinfo
  5.  
  6. xm,ym,zm=(0,0,0)
  7.  
  8. xscr=sysinfo.display_pixels()[0]
  9. yscr=sysinfo.display_pixels()[1]
  10. ofstars=600
  11. sz=1
  12. WHITE=0xffffff
  13. BLACK=0x000000
  14.  
  15. spanse = 700 # 700 should be the minimum
  16. xv=xscr/2
  17. yv=yscr/2
  18. slow = 800
  19.  
  20. moveX=range(ofstars)
  21. moveY=range(ofstars)
  22. moveZ=range(ofstars)
  23. XX=range(ofstars)
  24. YY=range(ofstars)
  25. ZZ=range(ofstars)
  26.  
  27. for i in range(ofstars):
  28.     XX[i]=random.randint(0,spanse)
  29.     YY[i]=random.randint(0,spanse)
  30.     ZZ[i]=random.randint(0,slow)
  31.  
  32. def sector():
  33.     global moveX,moveY,moveZ,XX,YY,ZZ
  34.     img.clear(BLACK)
  35.     for i in range(ofstars):
  36.         XX[i]+=int(xm*3.2)
  37.         YY[i]+=int(ym*3.2)
  38.         ZZ[i]+=int(zm*3.2)
  39.         if(XX[i]>spanse):
  40.             XX[i] -= spanse
  41.         elif(XX[i]<0):
  42.             XX[i] += spanse
  43.         if(YY[i]>spanse):
  44.             YY[i] -= spanse
  45.         elif(YY[i]<0):
  46.             YY[i] += spanse
  47.         if(ZZ[i]>slow):
  48.             ZZ[i] -= slow
  49.             XX[i]=random.randint(0,spanse)
  50.             YY[i]=random.randint(0,spanse)
  51.         elif(ZZ[i]<0):
  52.             ZZ[i] += slow
  53.             XX[i]=random.randint(0,spanse)
  54.             YY[i]=random.randint(0,spanse)
  55.  
  56.         ### start of main 3D effect
  57.         sz=ZZ[i]*0.07
  58.         px=XX[i]+((XX[i]-xv)*(ZZ[i]/100.0))
  59.         py=YY[i]+((YY[i]-yv)*(ZZ[i]/100.0))
  60.  
  61.         ### line ended of main 3D effect
  62.  
  63.         img.ellipse([(px,py),(px+sz,py+sz)],WHITE,fill=WHITE)
  64.     img.text((20,40),'X:'+unicode(xm),(WHITE))
  65.     img.text((20,80),'Y:'+unicode(ym),(WHITE))
  66.     canvas.blit(img,(0,0))
  67.     timer.after(0.02,sector)
  68.     draw(img)
  69.  
  70. def draw(rect):
  71.     appuifw.e32.reset_inactivity()
  72.  
  73. def exit(pos):
  74.     app_lock.signal()
  75.  
  76. def redraw():
  77.     global xm,ym,zm
  78.     ym,xm,zm=(sens.x/5,sens.y/5,sens.z/5)
  79.     '''
  80.     ym+=40
  81.     if ym > 25:
  82.         ym = 25
  83.     if ym < -25:
  84.         ym = -25
  85.     '''
  86.     draw(canvas.size)
  87.  
  88. '''
  89. def forLight():
  90.     appuifw.e32.reset_inactivity()
  91.     timer.after(10,forLight)
  92.  
  93. timer=appuifw.e32.Ao_timer()
  94. forLight()
  95. '''
  96.  
  97. img=graphics.Image.new((xscr,yscr))
  98. appuifw.app.directional_pad=False
  99. canvas=appuifw.Canvas(redraw_callback=draw)
  100. appuifw.app.body=canvas
  101. canvas.bind(key_codes.EButton1Down,exit)
  102. sens=sensor.AccelerometerXYZAxisData(data_filter=sensor.LowPassFilter())
  103. sens.set_callback(data_callback=redraw)
  104. sens.start_listening()
  105. appuifw.app.screen='full'
  106.  
  107. timer=appuifw.e32.Ao_timer()
  108. appuifw.app.orientation='landscape'
  109. sector()
  110. e32.ao_yield()
  111.  
  112. app_lock=appuifw.e32.Ao_lock()
  113. app_lock.wait()
  114. sens.stop_listening()
  115. timer.cancel()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement