Advertisement
Guest User

startup.lua

a guest
Feb 25th, 2020
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.78 KB | None | 0 0
  1. --- Variables
  2. local mfsu1 = peripheral.wrap("ic2:mfsu_1")
  3. local mfsu2 = peripheral.wrap("ic2:mfsu_2")
  4. local mon = peripheral.wrap("top")
  5. local rx,ry = mon.getSize()
  6.  
  7. -- text
  8. local headLine = "EU Power Storage"
  9.  
  10. -- colors
  11. local bc = colors.black
  12. local tc = colors.white
  13. local bar = colors.lime
  14. local barOff = colors.gray
  15.  
  16. --- Functions
  17. function drawIntro()
  18.  mon.setBackgroundColor(bc)
  19.  mon.setTextColor(tc)
  20.  mon.clear()
  21.  mon.setBackgroundColor(colors.gray)
  22.  mon.setCursorPos(1, 1)
  23.  mon.clearLine()
  24.  mon.setCursorPos(math.floor((rx/2)-(string.len(headLine))/2)+1, 1)
  25.  mon.write(headLine)
  26. end
  27.  
  28. function drawBar(x, y, text, name)
  29.  mon.setBackgroundColor(bc)
  30.  mon.setTextColor(tc)
  31.  if(name=="mfsu1") then
  32.   ene = mfsu1.getEUStored()
  33.   cap = mfsu1.getEUCapacity()
  34.  elseif(name=="mfsu2") then
  35.   ene = mfsu2.getEUStored()
  36.   cap = mfsu2.getEUCapacity()
  37.  end
  38.  local per = math.ceil((ene/cap)*100)
  39.  local pro = math.ceil(((rx-1)/100)*per)
  40.  
  41.  mon.setCursorPos(x, y)
  42.  mon.write(text.." - "..ene.." / "..cap)
  43.  
  44.  if(per<15) then
  45.   mon.setBackgroundColor(colors.red)
  46.  elseif(per>15 and per<30) then
  47.   mon.setBackgroundColor(colors.orange)
  48.  else
  49.   mon.setBackgroundColor(bar)
  50.  end
  51.  
  52.  for i = x, pro do
  53.   mon.setCursorPos(i, y+1)
  54.   mon.write(" ")
  55.   mon.setCursorPos(i, y+2)
  56.   mon.write(" ")
  57.   mon.setCursorPos(i, y+3)
  58.   mon.write(" ")
  59.  end
  60.  
  61.  mon.setBackgroundColor(barOff)
  62.  
  63.  for i = pro, rx-1 do
  64.   if(i<x) then
  65.    i=x
  66.   end
  67.   mon.setCursorPos(i, y+1)
  68.   mon.write(" ")
  69.   mon.setCursorPos(i, y+2)
  70.   mon.write(" ")
  71.   mon.setCursorPos(i, y+3)
  72.   mon.write(" ")
  73.  end
  74.  
  75. end
  76.  
  77. function draw()
  78.  drawBar(2, 3, "MFSU 1", "mfsu1")
  79.  drawBar(2, 8, "MFSU 2", "mfsu2")
  80. end
  81.  
  82. --- Execute
  83. function init()
  84.  drawIntro()
  85.  while true do
  86.   draw()
  87.   sleep(0.5)
  88.  end
  89. end
  90.  
  91. init()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement