Advertisement
billysback

Timer

Sep 24th, 2013
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.20 KB | None | 0 0
  1. local args = {...}
  2. local mins = 30
  3. if args[1] ~= nil then mins = tonumber(args[1]) end
  4.  
  5. local mins30 = mins*60
  6.  
  7. local on = true
  8. local signal = true
  9.  
  10. local function doSignal()
  11.     redstone.setOutput("back", signal)
  12. end
  13.  
  14. local width, height = term.getSize()
  15. local function draw(per)
  16.     local perw = math.floor((width/100)*per)
  17.     local perc = math.ceil( ((width/100)*(per+1)) - math.floor((width/100)*per) )/100
  18.     for x=1,width do
  19.         local char = " "
  20.         for y=1,height do
  21.             if x <= perw then
  22.                 if x == perw then
  23.                     if y <= perc then char = "%" else char = " " end
  24.                 else
  25.                     char = "%"
  26.                 end
  27.             end
  28.             term.setCursorPos(x, y)
  29.             local col = colors.lime
  30.             if not signal then col = colors.red end
  31.             term.setBackgroundColor(col)
  32.             term.setTextColor(colors.white)
  33.             term.write(char)
  34.         end
  35.     end
  36. end
  37.  
  38. local t = 0
  39. local percent = mins30/100
  40. local timer = os.startTimer(percent)
  41.  
  42. while on do
  43.     local event, p1 = os.pullEvent()
  44.     if event == "key" then
  45.         if p1 == 29 then
  46.             on = false
  47.         end
  48.     elseif event == "timer" and timer == p1 then
  49.         t = t + 1
  50.         if t >= 100 then
  51.             signal = (signal == false)
  52.             t = 0
  53.         end
  54.         doSignal()
  55.         draw(t)
  56.         timer = os.startTimer(percent)
  57.     end
  58. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement