Advertisement
momo5502

Vortex (Zoom)

Nov 12th, 2014
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.39 KB | None | 0 0
  1. return function(page, offset, screen_width, screen_height)
  2.     local percent = math.abs(offset/page.width)
  3.    
  4.     local centerX = page.width/2
  5.     local centerY = page.height/2+7
  6.    
  7.     local const = 1.5
  8.     local scale = percent - 0.35
  9.     local factor = 20
  10.    
  11.     if scale < 0 then scale = 0 end
  12.    
  13.     local radius = 0.60 * page.width / const
  14.     if radius > page.height then radius = 0.60 * page.height / (const + factor * scale)
  15.     else radius = 0.60 * page.width / (const + factor * scale) end
  16.    
  17.     local theta = (2*math.pi)/#page.subviews
  18.    
  19.     local endStage1P = 1/3
  20.     local endStage2P = 2/3
  21.    
  22.     local stage1P = percent*(1/endStage1P)
  23.     if (stage1P > 1) then stage1P = 1 end
  24.    
  25.     local stage2P = (percent-endStage1P)*(1/(endStage2P-endStage1P))
  26.     if (stage2P > 1) then stage2P = 1
  27.     elseif (stage2P < 0) then stage2P = 0 end
  28.    
  29.     for i, icon in subviews(page) do
  30.         local iconAngle = theta*(i-1) - math.pi/6 + stage2P*(math.pi/3)
  31.        
  32.         local begX = icon.x+icon.width/2
  33.         local begY = icon.y+icon.height/2
  34.        
  35.         local endX = centerX+radius*math.cos(iconAngle)
  36.         local endY = centerY-radius*math.sin(iconAngle)
  37.        
  38.         icon:translate((endX-begX)*stage1P, (endY-begY)*stage1P, 0)
  39.         icon:rotate(-stage1P*((math.pi/2) + iconAngle))
  40.     end
  41.    
  42.     page.alpha = 1 - stage2P
  43.     page:translate(offset, 0, 0)
  44. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement