Guest User

ComputerCraft progress bar

a guest
Nov 28th, 2017
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.76 KB | None | 0 0
  1.  
  2.   local reactor0 = peripheral.wrap("BigReactors-Reactor_0")
  3.   local reactor5 = peripheral.wrap("BigReactors-Reactor_5")
  4.   local reactor1 = peripheral.wrap("BigReactors-Reactor_1")
  5.   local reactor2 = peripheral.wrap("BigReactors-Reactor_2")  
  6.   local batcurrent = peripheral.wrap("tile_enderio_blockcapacitorbank_name_1")
  7.   local curpull = reactor0.getEnergyProducedLastTick()+reactor5.getEnergyProducedLastTick()+reactor1.getEnergyProducedLastTick()+reactor2.getEnergyProducedLastTick()
  8.   local mon = peripheral.wrap("monitor_3")
  9.  
  10. term.clear()
  11. term.setCursorPos(1,1)
  12. --term.write(math.floor(reactor0.getEnergyProducedLastTick()+reactor5.getEnergyProducedLastTick()+reactor1.getEnergyProducedLastTick()+reactor2.getEnergyProducedLastTick()))
  13.  
  14.  
  15. --confusing progress bar shit--------------------------------------------
  16.  
  17. monX, monY = mon.getSize()
  18.  
  19. function clear()
  20.   mon.setBackgroundColor(colors.black)
  21.   mon.clear()
  22.   mon.setCursorPos(1,1)
  23. end
  24.  
  25. function drawText(x, y, text, color_txt, color_bg)
  26.   mon.setBackgroundColor(color_bg)
  27.   mon.setTextColor(color_txt)
  28.   mon.setCursorPos(x,y)
  29.   mon.write(text)
  30. end
  31.  
  32. function drawLine(x, y, length, size, color_bar)
  33.   for yPos = y, y+size-1 do
  34.     mon.setBackgroundColor(color_bar)
  35.     mon.setCursorPos(x, yPos)
  36.     mon.write(string.rep(" ", length))
  37.   end
  38. end
  39.  
  40. function drawProg(x, y, name, length, size, minVal, maxVal, color_bar, color_bg)
  41.   drawLine(x, y, length, size, color_bg)
  42.   local barSize = math.floor((minVal/maxVal)*length)
  43.   drawLine(x, y, barSize, size, color_bar)
  44.  local text = name.." "..math.floor((minVal/maxVal)*100).."%"
  45.   if barSize > length/2+#text/2 then
  46.     drawText(x+length/2-#text/2, y+size/2, text, colors.black, color_bar)
  47.   elseif barSize > #text then
  48.     drawText((x+barSize)-#text, y+size/2, text, colors.black, color_bar)
  49.   else
  50.     drawText(x+length/2-#text/2, y+size/2, text, colors.black, color_bg)
  51.   end
  52. end
  53.  
  54.  
  55. --progress bar-----------------------------------------------------------------------------------------------------
  56.  
  57.  
  58.  
  59. mon.clear()
  60. mon.setBackgroundColor(colors.black)
  61.  
  62. --for i = batcurrent.getEnergyStored("unknown"), batcurrent.getMaxEnergyStored("unknown") do
  63.   drawProg(3,1, "Capacitor", 46, 2, batcurrent.getEnergyStored("unknown"), batcurrent.getMaxEnergyStored("unknown"), colors.green, colors.gray)
  64.     mon.setBackgroundColor(colors.black)
  65.       term.setTextColor(colors.red)
  66.         print((math.floor(curpull)))
  67.  
  68. --end
  69.  
  70. --for i = curpull, 7580 do
  71.   drawProg(3,4, "Current Output", 46, 2, curpull, 7580, colors.red, colors.gray)
  72.     mon.setBackgroundColor(colors.black)
  73.       term.setTextColor(colors.blue)
  74.         print((math.floor(curpull)))
  75.           mon.setBackgroundColor(colors.black)
  76.  
  77. --end
  78.  
  79. sleep(3)
  80.  
  81. print("end")
  82.  
  83. sleep(1)
  84. os.reboot()
Advertisement
Add Comment
Please, Sign In to add comment