Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- Draws a progress bar. It will write directly to the monitor.
- -- @param text the text to overlay onto the progress bar. It will be offset 1 pixel.
- -- @param width the width of the progress bar
- -- @param current the current value of the progress being drawn
- -- @param max the max value of the progress being drawn
- --
- function drawProgressBar(text, width, current, max)
- local ratio = current / max
- for i = 0, width do
- local currentText = " "
- local textIndex = i - 1 -- start writing after the first box
- if i > 0 and textIndex <= #text then
- currentText = text:sub(textIndex, textIndex)
- end
- if i / width <= ratio then
- monitor.setTextColor(colors.black)
- monitor.setBackgroundColor(colors.lime)
- monitor.write(currentText)
- else
- monitor.setTextColor(colors.black)
- monitor.setBackgroundColor(colors.red)
- monitor.write(currentText)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement