Advertisement
here2share

# 8dots3Dspin.py

Dec 25th, 2014
376
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # 8dots3Dspin.py
  2.  
  3. import math,e32,appuifw,graphics,key_codes,time
  4.  
  5. def draw(rect):
  6.     try: c.blit(img)
  7.     except: pass
  8.  
  9. xm,ym = 0,0
  10. def redraw():
  11.     global xm,ym
  12.     ym,xm,zm=(sens.x/2.0,sens.y/2.0,sens.z/2.0) ### Z axis is not needed
  13.  
  14. def exit(pos):
  15.     global run
  16.     run=0
  17.  
  18. run = 1
  19. img=graphics.Image.new((640,360))
  20. appuifw.app.directional_pad=False
  21. c=appuifw.Canvas(redraw_callback=draw)
  22. appuifw.app.body=c
  23. c.bind(key_codes.EButton1Down,exit)
  24. #sens=sensor.AccelerometerXYZAxisData(data_filter=sensor.LowPassFilter())
  25. #sens.set_callback(data_callback=redraw)
  26. #sens.start_listening()
  27. appuifw.app.orientation='landscape'
  28. appuifw.app.screen='full'
  29.  
  30. halfResX = c.size[0]/2
  31. halfResY = c.size[1]/2
  32. distance = 180
  33.  
  34. PX = 0
  35. PY = 0
  36. PZ = 200
  37. Size = 10
  38. xyz=80
  39. VX = [-xyz, xyz, -xyz, xyz, -xyz, xyz, -xyz, xyz]
  40. VY = [-xyz, -xyz, xyz, xyz, -xyz, -xyz, xyz, xyz]
  41. VZ = [-xyz, -xyz, -xyz, -xyz, xyz, xyz, xyz, xyz]
  42. ANGLEX = 0
  43. ANGLEY = 0
  44. ANGLEZ = 0
  45.  
  46. while run:
  47.     rax = ANGLEX*math.pi/180
  48.     ray = ANGLEY*math.pi/180
  49.     raz = ANGLEZ*math.pi/180
  50.  
  51.     sinx = math.sin(rax)
  52.     cosx = math.cos(rax)
  53.     siny = math.sin(ray)
  54.     cosy = math.cos(ray)
  55.     sinz = math.sin(raz)
  56.     cosz = math.cos(raz)
  57.  
  58.     try:
  59.         for n in record:
  60.             x,y,z = n
  61.             img.point((x,y),0xffffff,width=z)
  62.     except:pass
  63.  
  64.     record=[]
  65.     for n in range(8):
  66.         ZX = VX[n]*cosz - VY[n]*sinz - VX[n]
  67.         ZY = VX[n]*sinz + VY[n]*cosz - VY[n]
  68.         YX = (VX[n]+ZX)*cosy - VZ[n]*siny - (VX[n]+ZX)
  69.         YZ = (VX[n]+ZX)*siny + VZ[n]*cosy - VZ[n]
  70.         XY = (VY[n]+ZY)*cosx - (VZ[n]+YZ)*sinx - (VY[n]+ZY)
  71.         XZ = (VY[n]+ZY)*sinx + (VZ[n]+YZ)*cosx - (VZ[n]+YZ)
  72.         XR = YX+ZX
  73.         YR = ZY+XY
  74.         ZR = XZ+YZ
  75.         z = (VZ[n]+PZ+ZR)/distance
  76.         x = ((VX[n]+PX+XR)/z)+halfResX
  77.         y = ((VY[n]+PY+YR)/z)+halfResY
  78.         z = int(Size/z)
  79.         img.point((int(x),int(y)),0x0000ff,width=z)
  80.         record.append((x,y,z))
  81.     img.point((PX+halfResX,PY+halfResY),0xff0000,width=Size*3)
  82.  
  83.     ANGLEX+=1
  84.     ANGLEY+=1
  85.     ANGLEZ+=1
  86.     draw(())
  87.  
  88.     wait=time.time()+0.005 ### ZZZ might flicker with a less wait
  89.     while time.time() < wait:
  90.         pass
  91.     e32.ao_yield()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement