Advertisement
Guest User

reactor_mon.lua

a guest
Apr 6th, 2020
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.42 KB | None | 0 0
  1. local monitor = peripheral.find("monitor")
  2. local reactor = peripheral.find("BigReactors-Reactor")
  3.  
  4. local rodSize = 4
  5.  
  6. function clear()
  7.     term.clear()
  8.     term.setBackgroundColor(colors.black)
  9.     term.setCursorPos(1,1)
  10. end
  11.  
  12. function drawRods(sx, sy)
  13.  
  14.     local controlRods = reactor.getNumberOfControlRods()
  15.  
  16.     for i=1,controlRods do
  17.         term.setCursorPos(1,1)
  18.         local percent = reactor.getControlRodLevel(i-1)/100.0
  19.        
  20.         local h = math.floor(percent*rodSize)
  21.        
  22.         if percent == 1 then
  23.             h = rodSize-1
  24.         end
  25.        
  26.         local left = (rodSize-h)-1
  27.         local x = sx+i*2
  28.         local y = sy
  29.        
  30.         if i > 10 then
  31.             y = y + rodSize+1
  32.             x = sx + (i-10)*2
  33.         end
  34.        
  35.         --write(tostring(i)..' '..tostring(h))
  36.         --x,y,width,height
  37.         paintutils.drawFilledBox(x, y, x, y+h, colours.green)
  38.        
  39.         if percent < 1 then
  40.           paintutils.drawFilledBox(x, y+h, x, (y+h)+left, colours.red)
  41.         end
  42.     end
  43.  
  44.     term.setBackgroundColor(colours.black)
  45. end
  46.  
  47. function drawHeader()
  48.     local activeText = "Active"
  49.    
  50.     if not reactor.getActive() then
  51.         activeText = "Disabled"
  52.     end
  53.    
  54.     write("Reactor"..activeText.."\n")
  55. end
  56.  
  57. term.redirect(monitor)
  58. monitor.setTextScale(0.5)
  59.  
  60. while true do
  61.     clear()
  62.     drawHeader()
  63.     drawRods(1, 4)
  64.     sleep(5)
  65. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement