Advertisement
Guest User

Untitled

a guest
May 7th, 2014
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.99 KB | None | 0 0
  1. --- Draws a progress bar. It will write directly to the monitor.
  2. -- @param text the text to overlay onto the progress bar. It will be offset 1 pixel.
  3. -- @param width the width of the progress bar
  4. -- @param current the current value of the progress being drawn
  5. -- @param max the max value of the progress being drawn
  6. --
  7. function drawProgressBar(text, width, current, max)
  8.     local ratio = current / max
  9.  
  10.     for i = 0, width do
  11.         local currentText = " "
  12.  
  13.         local textIndex = i - 1 -- start writing after the first box
  14.         if i > 0 and textIndex <= #text then
  15.             currentText = text:sub(textIndex, textIndex)
  16.         end
  17.  
  18.         if i / width <= ratio then
  19.             monitor.setTextColor(colors.black)
  20.             monitor.setBackgroundColor(colors.lime)
  21.             monitor.write(currentText)
  22.         else
  23.             monitor.setTextColor(colors.black)
  24.             monitor.setBackgroundColor(colors.red)
  25.             monitor.write(currentText)
  26.         end
  27.     end
  28. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement