Advertisement
Guest User

kiwi

a guest
Apr 6th, 2020
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.27 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.  
  10. function checkPower()
  11.     max = mat.getMaxEnergy()
  12.     cur = mat.getEnergy()
  13.     per = math.floor((cur/max)*100+0.5)
  14.    -- mon.write(per)
  15. end
  16.  
  17. function writeMon()
  18.     mon.setBackgroundColor(colors.black)
  19.     mon.clear()
  20.     mon.setCursorPos(1,1)
  21.     Text("  Kiwi-Powerstatus  ", 1, colors.white, colors.red)
  22.     Text(" Füllstand: " .. per .. "% ", y-5, colors.black, colors.red)
  23. end
  24.  
  25. function barDraw()
  26.     local bar = math.floor((cur/max)*(x-2))+0.5
  27.     mon.setCursorPos(2,y-4)
  28.     mon.setBackgroundColor(colors.blue)
  29.     mon.write(string.rep(" ", x-2))
  30.    
  31.     mon.setCursorPos(2, y-4)
  32.     mon.setBackgroundColor(colors.red)
  33.     mon.write(string.rep(" ", bar))
  34. end
  35.  
  36. function Text(text, line, colB, colT)
  37.     mon.setBackgroundColor(colB)
  38.     mon.setTextColor(colT)
  39.     local ts = string.len(text)
  40.     local dif = math.floor(x-ts)
  41.     local _x = math.floor(dif/2)
  42.     mon.setCursorPos(_x+1, line)
  43.     mon.write(text)
  44. end
  45.  
  46. while true do
  47.     checkPower()
  48.     writeMon()
  49.     barDraw()
  50.     print(cur .. "/" .. max.." - "..per.."%")
  51.     sleep(1)
  52. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement