QuickMuffin8783

UI API (version 1.0.0) (CC Only)

Jun 27th, 2020 (edited)
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.64 KB | None | 0 0
  1. function drawProgBar(done, max, x, y, wide, colorBright, colorDark)
  2.     local oldX, oldY = term.getCursorPos()
  3.     local oldBC = term.getBackgroundColor()
  4.     local oldTC = term.getTextColor()
  5.     local val = done / max
  6.     term.setBackgroundColor(colors.black)
  7.     term.setTextColour(colors.black)
  8.     if oldBC == colors.black then
  9.         term.setBackgroundColor(colors.black)
  10.         term.setTextColor(colors.gray)
  11.     end
  12.     term.setCursorPos(x,y)
  13.     write((string.char(153)):rep(wide))
  14.     term.setTextColor(colorDark)
  15.     term.setBackgroundColor(colorBright)
  16.     term.setCursorPos(x,y)
  17.     write((string.char(153)):rep(math.floor(val
  18.      * wide)))
  19.     term.setBackgroundColor(oldBC)
  20.     term.setTextColour(oldTC)
  21.     term.setCursorPos(oldX, oldY)
  22. end
  23.  
  24. function calcPercent(done, max)
  25.     local val = done / max
  26.     local per = math.floor(val * 100)
  27.     return per
  28. end
  29.  
  30. function tableCount(t)
  31.     local table = t
  32.     local count = 0
  33.     for _ in pairs(table) do
  34.         count = count + 1
  35.     end
  36.     return count
  37. end
  38.  
  39. function smoothAdd(fromNum, toNum, speed)
  40.     return ((toNum - fromNum) / (speed or 10))
  41. end
  42.  
  43. local demo = false
  44.  
  45. local per = 0
  46. local change = 0.1
  47. local max = 10
  48. local w, h = term.getSize()
  49. while demo do
  50.     w, h = term.getSize()
  51.     if per > max then
  52.         per = max
  53.         change = -0.1
  54.     end
  55.     if per < 0 then
  56.         per = 0
  57.         change = 0.1
  58.     end
  59.     drawProgBar(per, max, 2, 2, 5, colors.green, colors.lime)
  60.     drawProgBar(per, max, 2, 4, 10, colors.blue, colors.cyan)
  61.     drawProgBar(per, max, 2, 6, 15, colors.red, colors.orange)
  62.     per = per + change
  63.     sleep(0.1)
  64. end
Add Comment
Please, Sign In to add comment