Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- imonitor = {}
- local monitor
- local function round(num)
- return math.floor(num + 0.5)
- end
- function exact_send(x, y, msg)
- monitor.setCursorPos(x,y)
- monitor.write(msg)
- end
- local function getCX(msg)
- local width, height = monitor.getSize()
- local length = string.len(msg)
- local cx = round(((width+1)-length)/2)
- return cx
- end
- function f_send(pos, y, msg)
- local length = string.len(msg)
- local width, height = monitor.getSize()
- if pos == "RIGHT" then
- exact_send(width-length, y, msg)
- elseif pos == "CENTER" then
- local cx = round(((width+1)-length)/2)
- exact_send(cx, y, msg)
- elseif pos == "LEFT" then
- exact_send(1, y, msg)
- else
- error("Invalid argument: "..pos)
- end
- end
- function c_send(y, msg)
- f_send("CENTER", y, msg)
- end
- function r_send(y, msg)
- f_send("RIGHT", y, msg)
- end
- function l_send(y, msg)
- f_send("LEFT", y, msg)
- end
- --x can be a # or a position ('LEFT', 'RIGHT', 'CENTER')
- function send(x, y, msg)
- if type(x) == "string" then
- f_send(x, y, msg)
- return
- end
- exact_send(x, y, msg)
- end
- function draw_color_bar(x, y, color, percent)
- send(x,y,"[")
- local limit = round(percent/10)
- local oX = getCX(limit)
- for i = 0, limit, 1 do
- monitor.setCursorPos(getX(oX+i), y)
- monitor.blit(" ", color, color)
- end
- for i = limit, 9, 1 do
- send(getX(oX+i), y, " ")
- end
- send(getX(oX+9), y, "]")
- end
- function draw_bar(x, y, percent)
- local bar = "["
- local limit = round(percent/10)
- for i=0, limit, 1 do
- bar = bar.."="
- end
- for i=limit, 9, 1 do
- bar = bar.." "
- end
- bar = bar.."]"
- send(x, y, bar)
- end
- function setMonitor(some_monitor)
- monitor = some_monitor
- end
- return imonitor
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement