Advertisement
rhn

Energybar mon right bat bottom

rhn
Jun 26th, 2014
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.16 KB | None | 0 0
  1. local mon = peripheral.wrap("right")
  2. local ec = peripheral.wrap("bottom")
  3.  
  4. local monScale = 0.5
  5. mon.setTextScale(monScale)
  6. mon.setBackgroundColor(colors.black)
  7. mon.clear()
  8. local w,h = mon.getSize()
  9.  
  10. w = math.floor(w / 2)
  11.  
  12. print(w," ",h)
  13.  
  14. local col3 = {colors.red, colors.yellow, colors.green}
  15. local col5 = {colors.red, colors.orange, colors.yellow, colors.lime, colors.green}
  16. local col, ncol, n
  17.  
  18. if w % 3 < w % 5 then
  19.   col = col3
  20.   ncol = 3
  21.   w = w - (w % 3)
  22. else
  23.   col = col5
  24.   ncol = 5
  25.   w = w - (w % 5)
  26. end
  27.  
  28. n = w / ncol
  29.  
  30. local eNow, eMax, wOld, wNew
  31.  
  32. wNew = w
  33. local start = true
  34.  
  35. while true do
  36.   wOld = wNew
  37.   eNow = ec.getEnergyStored("right")
  38.   eMax = ec.getMaxEnergyStored("right")
  39.   wNew = math.ceil(w * eNow / eMax)
  40.  
  41.   if wOld ~= wNew or start then
  42.     start = false
  43.     mon.setBackgroundColor(colors.black)
  44.     mon.clear()
  45.  
  46.     for i = 1,wNew do
  47.       for j = 1,h do
  48.         mon.setCursorPos(i*2 - 1,j)
  49.         mon.setBackgroundColor(col[math.ceil(i/n)])
  50.         mon.write(" ")
  51.         mon.setCursorPos(i*2,j)
  52.         mon.setBackgroundColor(colors.black)
  53.         mon.write(" ")
  54.       end
  55.     end
  56.   end
  57.   sleep(1)
  58. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement