Guest User

Untitled

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