Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function findPeripheral(typeName)
- local function contains(str, find)
- if (str == nil or find == nil) then
- return true
- end
- if (string.find(str, find, 1) == nil) then
- return false
- end
- return true
- end
- local side
- side = peripheral.wrap("left")
- if (side ~= nil) then
- if (contains(peripheral.getType("left"), typeName)) then
- return side
- end
- end
- side = peripheral.wrap("front")
- if (side ~= nil) then
- if (contains(peripheral.getType("front"), typeName)) then
- return side
- end
- end
- side = peripheral.wrap("right")
- if (side ~= nil) then
- if (contains(peripheral.getType("right"), typeName)) then
- return side
- end
- end
- side = peripheral.wrap("back")
- if (side ~= nil) then
- if (contains(peripheral.getType("back"), typeName)) then
- return side
- end
- end
- side = peripheral.wrap("top")
- if (side ~= nil) then
- if (contains(peripheral.getType("top"), typeName)) then
- return side
- end
- end
- side = peripheral.wrap("bottom")
- if (side ~= nil) then
- if (contains(peripheral.getType("bottom"), typeName)) then
- return side
- end
- end
- return nil
- end
- function calculateCenter(w, text)
- return math.floor((w - string.len(text)) / 2) + 1
- end
- function writeMonitor(mon, x, y, text)
- mon.setCursorPos(x, y)
- mon.write(text)
- end
- function clearBackground(mon, colourr, textColour)
- mon.setBackgroundColor(colourr)
- mon.setTextColor(textColour)
- mon.clear()
- end
- function main()
- local monitor = findPeripheral("monitor")
- monitor.setTextScale(5)
- local line1 = "Particle"
- local line2 = "Station"
- while(true) do
- local w, h = monitor.getSize()
- local y = math.floor(h / 2)
- local x1 = calculateCenter(w, line1)
- local x2 = calculateCenter(w, line2)
- clearBackground(monitor, colours.black, colours.lime)
- writeMonitor(monitor, x1, y, line1)
- writeMonitor(monitor, x2, y + 1, line2)
- os.sleep(5)
- end
- end
- main()
Add Comment
Please, Sign In to add comment