Guest User

Untitled

a guest
Jun 4th, 2015
731
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. --[[ ******************************************************************
  2. Sphere by KnifeOfPi
  3. /u/rweichler, I expect my T-shirt!
  4.  
  5. ******************************************************************* ]]
  6. -- my apologies for the illegible code
  7. return function(pg, of, sw, sh)
  8.  
  9. pg:translate(of,0,0)
  10.  
  11. local pc, cx, cy, ops = math.abs(of/pg.width), pg.width/2, pg.height/2, of/pg.width
  12. -- target distance
  13. local midx =pg.width/2
  14.  
  15. local midy =pg.height/2+7
  16. local tg = pg.width
  17. local fx = pc*5
  18. if fx>1 then fx=1 end
  19. local side = -1
  20.  
  21. -- if(of>0) then side=1 end
  22. for i, ic in subviews(pg) do
  23. -- get icon center
  24. local icx, icy = (ic.x+ic.width/2), (ic.y+ic.height/2)
  25. -- get icon offset from page center
  26. local ox, oy = cx-icx, cy-icy
  27. -- get angle of icon position
  28. local ang = math.atan2(oy,ox)
  29. -- get hypotenuse
  30. local h = math.sqrt( ox^2+oy^2)
  31.  
  32. local iconX = ic.x+ic.width/2
  33. local fall = (1-pc^2)*h
  34. local iconY = ic.y+ic.height/2
  35. -- get hypotenuse extension
  36. local nh = math.sqrt((iconX-midx)^2+(iconY-midy)^2)
  37. local oh = fx*h+fx*tg
  38. -- directions
  39. local dx, dy, dxz, dyz = 1,1,1,1
  40. if icx<cx then dx=0 dxz=1 end
  41. if icx>cx then dx=-1 dxz=-1 end
  42. if icy<cy then dy=0 dyz=1 end
  43. if icy>cy then dy=-1 dyz=-1 end
  44. if icy==cy then dy=1 end
  45. local nx = 0
  46. local ny = 0
  47. -- calc new x & y
  48. -- local nx = math.sqrt(h^2-oy^2)
  49. -- local ny = math.sqrt(h^2-ox^2)
  50. nx = 0
  51. ny =0-h*math.sin(230/(h+50)*ops*2*math.pi+ang)
  52. local size=(3-fx)*(fall/h)
  53. if size>1 then size=1 end
  54. local w = pc-math.abs(ox/300)
  55. if w<0 then w=0 end
  56. local x=(pc-0.2)*5/4
  57. if x<0 then x=0 end
  58. local ry = oy
  59. -- move!
  60. -- print(ox)
  61. -- if fx<1 then ic:translate((fx)*ox, 0, 0) end
  62. ic:translate(fx*ox, 0)
  63. ic:rotate(ops*3*math.pi-fx*(1.6*ox/pg.width)*.8*math.pi, 0, 1, 0)
  64.  
  65. if fx<=10 then ic:translate(fx*.45*2.75*math.abs(math.abs(oy)-.5*pg.height), 0, 0) end
  66. ic:rotate(fx*.5*math.pi, 0, 1, 0)
  67. ic:rotate((fx*(math.abs(oy-7))/(pg.height))*.8*math.pi, dyz, 0, 0)
  68. -- ic:rotate(.5*math.pi, 0, 1, 0)
  69. -- viewFlip(pg, pc, 1, true)
  70. -- ic:scale(size*size)
  71. -- ic:translate(-0.5*nx,-0.5*ny,0)
  72.  
  73. -- if pc>0.6 then
  74. ic.alpha = 1-pc
  75. -- end
  76.  
  77. end
  78. end
Advertisement
Add Comment
Please, Sign In to add comment