Advertisement
Guest User

startup

a guest
Aug 20th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.29 KB | None | 0 0
  1. rednet.open("top")
  2. local mon = peripheral.wrap("monitor_38")
  3. monX, monY = mon.getSize()
  4.  
  5. function drawText(x, y, text, color_txt, color_bg)
  6.   mon.setTextScale(2)
  7.   mon.setBackgroundColor(color_bg)
  8.   mon.setTextColor(color_txt)
  9.   mon.setCursorPos(x, y)
  10.   mon.write(text)
  11. end
  12.  
  13. function drawLine(x, y, length, size, color_bg)
  14.   for yPos = y, y+size-1 do
  15.     mon.setBackgroundColor(color_bg)
  16.     mon.setCursorPos(x, yPos)
  17.     mon.write(string.rep(" ", length))
  18.   end
  19. end
  20.  
  21. function drawProg(x, y, txt, length, size, color_bg, color_bar, minVal, maxVal)
  22.   drawLine(x, y, length, size, color_bg)
  23.  
  24.   local barSize = math.floor((minVal/maxVal)*length)
  25.   drawLine(x, y, barSize, size, color_bar)
  26.  
  27.   local text = txt.." ".. math.floor((minVal/maxVal)*100).."%"
  28.   if barSize > length/2+#text/2 then
  29.     drawText(x+length/2-#text/2, y+size/2, text, colors.black, color_bar)
  30.   elseif barSize > #text then
  31.     drawText((x+barSize)-#text, y+size/2, text, colors.black, color_bar)
  32.   else
  33.     drawText(x+length/2-#text/2, y+size/2, text, colors.black, color_bg)
  34.   end
  35. end
  36.  
  37. function clear()
  38.   mon.setBackgroundColor(colors.black)
  39.   mon.clear()
  40. end
  41.  
  42. while true do
  43.   id, cmd = rednet.receive()
  44.   clear()
  45.   drawProg(2, 1, "Energy", monX-2, 1, colors.gray, colors.green, cmd, 100)
  46.   sleep(0.75)
  47. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement