Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local textScale = 1
- local textLines = {
- "",
- "Text",
- ""
- }
- -- Get all peripherals connected to the computer
- local monitors = {}
- for _, name in ipairs(peripheral.getNames()) do
- if peripheral.getType(name) == "monitor" then
- table.insert(monitors, peripheral.wrap(name))
- end
- end
- -- Ensure exactly two monitors are detected
- if #monitors ~= 2 then
- print("This script requires exactly two monitors connected to the computer.")
- return
- end
- -- Determine the monitors' sizes
- local mon1, mon2 = monitors[1], monitors[2]
- local width1, height1 = mon1.getSize()
- local width2, height2 = mon2.getSize()
- if height1 ~= height2 then
- print("Both monitors must have the same height.")
- return
- end
- mon1.setTextScale(textScale)
- mon2.setTextScale(textScale)
- -- Clear both monitors
- mon1.clear()
- mon2.clear()
- -- Display an array of text on both monitors
- local function displayTextOnMonitors(lines)
- local maxWidth = math.min(width1, width2)
- local yStart = math.floor((height1 - #lines) / 2)
- for i, line in ipairs(lines) do
- local y = yStart + i - 1
- if y > 0 and y <= height1 then
- local truncatedLine = line:sub(1, maxWidth)
- mon1.setCursorPos(math.floor((maxWidth - #truncatedLine) / 2), y)
- mon1.write(truncatedLine)
- mon2.setCursorPos(math.floor((maxWidth - #truncatedLine) / 2), y)
- mon2.write(truncatedLine)
- end
- end
- end
- displayTextOnMonitors(textLines)
Advertisement
Add Comment
Please, Sign In to add comment