Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local args = { ... }
- os.loadAPI("vislib")
- local m = peripheral.find("monitor")
- m.setTextScale(0.5)
- local monX, monY = m.getSize()
- local sx = math.floor(0.047 * monX + 0.8)
- local sy = math.floor(0.07 * monY + 0.8)
- local scrW = 16 * sx - 4
- local scrH = 16 * sy - 4
- local scrResX = (scrH / monY) / (scrW / monX)
- local f = monY / scrH
- local scrResX = scrResX * f
- local scrResY = f
- function round(num)
- return math.floor(num + 0.4)
- end
- function drawLine(x1, y1, x2, y2, color)
- m.setBackgroundColor(color)
- x1 = round(x1 * scrResX)
- x2 = round(x2 * scrResX)
- y1 = round(y1 * scrResY)
- y2 = round(y2 * scrResY)
- if math.abs(x2 - x1) > math.abs(y2 - y1) then
- for x = math.min(x1, x2), math.max(x1, x2) do
- if x > 0 and x <= monX then
- local y = round(y1 + 1.0 * (x - x1) * (y2 - y1) / (x2 - x1))
- if y > 0 and y <= monY then
- m.setCursorPos(x, y)
- m.write(" ")
- end
- end
- end
- else
- for y = math.min(y1, y2), math.max(y1, y2) do
- local x = x1 + 1.0 * (y - y1) * (x2 - x1) / (y2 - y1)
- m.setCursorPos(x, y)
- m.write(" ")
- end
- end
- end
- function drawRect(x, y, w, h, c)
- m.setBackgroundColor(c)
- local x1 = round((x + w) * scrResX)
- x = round(x * scrResX)
- local y1 = round((y + h) * scrResY)
- y = round(y * scrResY)
- if 0 < x1 and x <= monX and 0 < y1 and y <= monY then
- if x < 0 then x = 0 end
- if y < 0 then y = 0 end
- if x1 > monX then x1 = monX end
- if y1 > monY then y1 = monY end
- local txt = ""
- for x2 = x, x1 do
- txt = txt .. " "
- end
- for y2 = y, y1 do
- m.setCursorPos(x, y2)
- m.write(txt)
- end
- end
- end
- function getSize()
- local x, y = m.getSize()
- return x / scrResX, y / scrResY
- end
- function clear()
- m.setBackgroundColor(colors.black)
- m.clear()
- end
- if #args < 3 then error("3 arguments expected") end
- local screenName = args[1]
- local screenX = 0 --tonumber(args[2])
- local screenY = 0 --tonumber(args[3])
- local screenCX = tonumber(args[2])
- local screenCY = tonumber(args[3])
- local screenW, screenH = getSize()
- print("screen[" .. screenName .. "]: ", screenX, ", ", screenY, ", ", screenW, ", ", screenH)
- rednet.open("top")
- function main()
- local id, msg = vislib.receiveRednet()
- local tag, pts = vislib.getMsgData(msg)
- if tag == "@mon" and pts[1] == screenName then
- if pts[2] == "clear" then
- clear()
- elseif pts[2] == "line" then
- drawLine(tonumber(pts[3]) - screenX, tonumber(pts[4]) - screenY,
- tonumber(pts[5]) - screenX, tonumber(pts[6]) - screenY,
- tonumber(pts[7]))
- elseif pts[2] == "rect" then
- drawRect(tonumber(pts[3]) - screenX, tonumber(pts[4]) - screenY,
- tonumber(pts[5]), tonumber(pts[6]),
- tonumber(pts[7]))
- elseif pts[2] == "reboot" then
- os.reboot()
- elseif pts[2] == "sendData" then
- vislib.sendRednet(id, "@monman:" .. screenName .. ",monData," .. os.getComputerLabel() .. "," .. screenCX .. "," .. screenCY .. "," .. screenW .. "," .. screenH)
- elseif pts[2] == "setPos" then
- print("setPos:"..screenX..","..screenY)
- screenX = tonumber(pts[3])
- screenY = tonumber(pts[4])
- else print("unknown message: ", msg)
- end
- end
- end
- while true do
- local status, msg = pcall(main)
- if not status then
- if msg=="Terminated" then return end
- print("err: " .. msg)
- end
- end
- --pastebin run 0YB9PsQV startup={files={vislib=<pb:GYvMFCY5>,mon=<pb:aTJkv2dh>},cmds={{'mon',<input:'monitorName'>,<input:'x'>,<input:'y'>}}} label=<input:'Label'> reboot=true
- --cp disk/pastebin pastebin
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement