Advertisement
Reububble

Progress API

Jul 2nd, 2013
744
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.82 KB | None | 0 0
  1. -- Progression API
  2. -- [By Reububble] --
  3.  
  4. function sum()
  5.     wide,high=term.getSize()
  6.     term.setTextColor(2^15)
  7.     while true do
  8.         type,b=os.pullEvent('progress')
  9.         if b~=nil then
  10.             if b<1 then break end
  11.             term.setBackgroundColor(1)
  12.             for y=high/2-1,high/2+1 do
  13.                 term.setCursorPos(2,y)
  14.                 term.write(string.rep(' ',wide-2))
  15.             end
  16.             term.setCursorPos((wide-#tostring(b))/2,high/2)
  17.             term.write(b)
  18.         end
  19.     end
  20. end
  21.  
  22. function bar()
  23.     wide,high=term.getSize()
  24.     a,b,t=0,0,os.time()*50
  25.     pA = ""
  26.     pB = 0
  27.     pC = 0
  28.     pD = ""
  29.     term.setTextColor(2^15)
  30.     while true do
  31.         s1=os.time()*50
  32.         a=b
  33.         type,b=os.pullEvent("progress")
  34.         if b>=1 then
  35.             return
  36.         end
  37.         s2=os.time()*50
  38.         if s2<t then
  39.             t=t-600
  40.         end
  41.         term.setCursorPos(2,high/2-1)
  42.         term.setBackgroundColor(1)
  43.         term.write(string.rep(" ",wide-2))
  44.         pA="Time Elapsed : "..tostring(math.floor(s2-t))
  45.         term.setCursorPos((wide-#pA)/2,high/2-1)
  46.         term.write(pA)
  47.         term.setCursorPos(2,high/2+1)
  48.         term.write(string.rep(" ",wide-2))
  49.         if 2*s2-t-s1==0 then
  50.             pD="Time remaining : 0"
  51.         else
  52.             pD="Time remaining : "..tostring(math.ceil((1-b)*(((s2-t)/b)*(s2-t)+(s2-s1)*((s2-s1)/(b-a)))/(2*s2-t-s1)))
  53.         end
  54.         term.setCursorPos((wide-#pD)/2,high/2+1)
  55.         term.write(pD)
  56.         term.setCursorPos(2,high/2)
  57.         term.write(" ")
  58.         term.setBackgroundColor(2^14)
  59.         pC=math.floor(b*100).."%" --text
  60.         pB=math.floor(b*(wide-4)) --amound of Red
  61.         term.write(string.rep(" ",pB))
  62.         if pB>0 then
  63.             term.setCursorPos(3,high/2)
  64.             term.write(string.sub(pC,1,pB))
  65.         end
  66.         term.setBackgroundColor(2^5)
  67.         term.setCursorPos(pB+3,high/2)
  68.         term.write(string.rep(" ",math.ceil((1-b)*(wide-4))))
  69.         if pB<#pC then
  70.             term.setCursorPos(pB+3,high/2)
  71.             term.write(string.sub(pC,pB+1))
  72.         end
  73.         term.setBackgroundColor(1)
  74.         term.setCursorPos(wide-1,high/2)
  75.         term.write(" ")
  76.     end
  77. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement