Advertisement
Guest User

kiwi

a guest
Apr 6th, 2020
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.83 KB | None | 0 0
  1. local mat = peripheral.wrap("bottom")
  2. if mat == nil then return end
  3. local mon = peripheral.wrap("top")
  4. if mon == nil then return end
  5. --mon.clear()
  6.  
  7. local max, cur, per = 0, 0, 0
  8. local x, y = mon.getSize()
  9. local perIn, perOut = 0, 0
  10.  
  11. function checkPower()
  12.     max = mat.getMaxEnergy()
  13.     cur = mat.getEnergy()
  14.     per = math.floor((cur/max)*100+0.5)
  15.     perIn = math.floor((mat.getInput()/mat.getTransferCap())*100+0.5)
  16.     perOut = math.floor((mat.getOutput()/mat.getTransferCap())*100+0.5)
  17.    
  18.    -- mon.write(per)
  19. end
  20.  
  21. function writeMon()
  22.     mon.setBackgroundColor(colors.black)
  23.     mon.clear()
  24.     mon.setCursorPos(1,1)
  25.     Text("  Kiwi-Powerstatus  ", 1, colors.white, colors.red)
  26. end
  27.  
  28. function barDraw(bar, _y)
  29.     mon.setCursorPos(2,y-_y)
  30.     mon.setBackgroundColor(colors.blue)
  31.     mon.write(string.rep(" ", x-2))
  32.    
  33.     mon.setCursorPos(2, y-_y)
  34.     mon.setBackgroundColor(colors.red)
  35.     mon.write(string.rep(" ", bar))
  36. end
  37.  
  38. function Text(text, line, colB, colT)
  39.     mon.setBackgroundColor(colB)
  40.     mon.setTextColor(colT)
  41.     local ts = string.len(text)
  42.     local dif = math.floor(x-ts)
  43.     local _x = math.floor(dif/2)
  44.     mon.setCursorPos(_x+1, line)
  45.     mon.write(text)
  46. end
  47.  
  48. while true do
  49.     checkPower()
  50.     writeMon()
  51.    
  52.     -- in
  53.     Text(" Input: " .. perIn .. "% (" .. mat.getInput() .. " RF) ", y-15, colors.black, colors.red)
  54.     local bar = math.floor((mat.getInput()/mat.getTransferCap())*(x-2))+0.5
  55.     barDraw(bar, 14)
  56.     barDraw(bar, 13)
  57.     barDraw(bar, 12)
  58.     -- full
  59.     Text(" Füllstand: " .. per .. "% ", y-7, colors.black, colors.red)
  60.     barDraw(math.floor((cur/max)*(x-2))+0.5, 4)
  61.     barDraw(math.floor((cur/max)*(x-2))+0.5, 5)
  62.     barDraw(math.floor((cur/max)*(x-2))+0.5, 6)
  63.    
  64.     -- console
  65.     print(cur .. "/" .. max.." - "..per.."%")
  66.     sleep(1)
  67. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement