Guest User

new

a guest
Jul 30th, 2015
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.69 KB | None | 0 0
  1. mon = peripheral.wrap("left")
  2. core = peripheral.wrap("top")
  3. max = core.getMaxEnergyStored()
  4. monX, monY = mon.getSize()
  5.  
  6. function clear()
  7.   mon.setBackgroundColor(colors.black)
  8.   mon.clear()
  9.   mon.setCursorPos(1,1)
  10. end
  11. function title()
  12.   mon.setBackgroundColor(colors.black)
  13.   mon.setCursorPos(monX/2-5, 2)
  14.   mon.write("Power Status")
  15. end
  16. function current()  
  17.   mon.setBackgroundColor(colors.black)
  18.   mon.setCursorPos(monX/2-6, 6)
  19.   mon.write("Current Stored")
  20. end
  21. function drawText(x, y, text, color_txt, color_bg)
  22.   mon.setBackgroundColor(color_bg)
  23.   mon.setTextColor(color_txt)
  24.   mon.setCursorPos(x,y)
  25.   mon.write(text)
  26. end
  27. function drawLine(x, y, length, size, color_bar)
  28.   for yPos = y, y+size-1 do
  29.    mon.setBackgroundColor(color_bar)
  30.    mon.setCursorPos(x, yPos)
  31.    mon.write(string.rep(" ", length))
  32.   end
  33. end
  34.  
  35. function drawProg(x, y, name, length, size, minVal, maxVal, color_bar, color_bg)
  36.   drawLine(x, y, length, size, color_bg)
  37.   local barSize = math.floor((minVal/maxVal)*length)
  38.   drawLine(x, y, barSize, size, color_bar)
  39.   local text = name.." "..math.floor((minVal/maxVal)*100).."%"
  40.     if barSize > monX/2+#text/2 then
  41.       drawText(monX/2-#text/2, y+size/2, text, colors.black, colors.green)
  42.     elseif barSize > #text then
  43.       drawText((x+barSize)-#text, y+size/2, text, colors.black, colors.green)
  44.     else
  45.       drawText(monX/2-#text/2+2, y+size/2, text, colors.black, colors.gray)
  46.     end
  47. end
  48.  
  49. clear()
  50. while true do
  51.   stored = core.getEnergyStored()
  52.   title()
  53.   mon.setCursorPos(1,4)
  54.   mon.write("---------------------------------------")
  55.   current()
  56.   drawProg(3, 7, stored , monX-4, 2, stored, max, colors.green, colors.gray)
  57.   sleep(1)
  58.  
  59. end
Advertisement
Add Comment
Please, Sign In to add comment