Advertisement
teru

analog clock drive

Jul 18th, 2012
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.71 KB | None | 0 0
  1. --Alternate drive code for Jousway's analog clock.
  2.  
  3. local fHour=nil
  4. local fMinute=nil
  5. local fSecond=nil
  6. local bBegun=false
  7.  
  8. function fpmod(num,mod)
  9.     assert(num>=0 and mod>0)
  10.     return num-(mod*math.floor(num/mod))
  11. end
  12.  
  13. local function sync(slef)
  14.     local iStart=Second()
  15.     while Second()==iStart do
  16.         slef:sleep(0.001)
  17.     end
  18. end
  19.  
  20. local function TimeUpdate(s,fDelta)
  21.     if not bBegun then
  22.         fDelta=0
  23.         sync(s)
  24.         fHour=Hour()%12
  25.         fMinute=Minute()
  26.         fSecond=Second()
  27.     end
  28.     fHour=fpmod(fHour+(fDelta/3600),12)
  29.     fMinute=fpmod(fMinute+(fDelta/60),60)
  30.     fSecond=fpmod(fSecond+fDelta,60)
  31.     s:GetChild("one"):rotationz(fHour*30)
  32.     s:GetChild("two"):rotationz(fMinute*6)
  33.     s:GetChild("three"):rotationz(fSecond*6)
  34. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement