bobmarley12345

iek

May 4th, 2021 (edited)
459
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.22 KB | None | 0 0
  1. function findPeripheral(typeName)
  2.     local function contains(str, find)
  3.         if (str == nil or find == nil) then
  4.             return true
  5.         end
  6.         if (string.find(str, find, 1) == nil) then
  7.             return false
  8.         end
  9.         return true
  10.     end
  11.     local side
  12.     side = peripheral.wrap("left")
  13.     if (side ~= nil) then
  14.         if (contains(peripheral.getType("left"), typeName)) then
  15.             return side
  16.         end
  17.     end
  18.     side = peripheral.wrap("front")
  19.     if (side ~= nil) then
  20.         if (contains(peripheral.getType("front"), typeName)) then
  21.             return side
  22.         end
  23.     end
  24.  
  25.     side = peripheral.wrap("right")
  26.     if (side ~= nil) then
  27.         if (contains(peripheral.getType("right"), typeName)) then
  28.             return side
  29.         end
  30.     end
  31.  
  32.     side = peripheral.wrap("back")
  33.     if (side ~= nil) then
  34.         if (contains(peripheral.getType("back"), typeName)) then
  35.             return side
  36.         end
  37.     end
  38.  
  39.     side = peripheral.wrap("top")
  40.     if (side ~= nil) then
  41.         if (contains(peripheral.getType("top"), typeName)) then
  42.             return side
  43.         end
  44.     end
  45.  
  46.     side = peripheral.wrap("bottom")
  47.     if (side ~= nil) then
  48.         if (contains(peripheral.getType("bottom"), typeName)) then
  49.             return side
  50.         end
  51.     end
  52.  
  53.     return nil
  54. end
  55.  
  56. function calculateCenter(w, text)
  57.     return math.floor((w - string.len(text)) / 2) + 1
  58. end
  59.  
  60. function writeMonitor(mon, x, y, text)
  61.     mon.setCursorPos(x, y)
  62.     mon.write(text)
  63. end
  64.  
  65. function clearBackground(mon, colourr, textColour)
  66.     mon.setBackgroundColor(colourr)
  67.     mon.setTextColor(textColour)
  68.     mon.clear()
  69. end
  70.  
  71. function main()
  72.     local monitor = findPeripheral("monitor")
  73.     monitor.setTextScale(5)
  74.     local line1 = "Particle"
  75.     local line2 = "Station"
  76.  
  77.     while(true) do
  78.         local w, h = monitor.getSize()
  79.         local y = math.floor(h / 2)
  80.         local x1 = calculateCenter(w, line1)
  81.         local x2 = calculateCenter(w, line2)
  82.  
  83.         clearBackground(monitor, colours.black, colours.lime)
  84.         writeMonitor(monitor, x1, y, line1)
  85.         writeMonitor(monitor, x2, y + 1, line2)
  86.  
  87.         os.sleep(5)
  88.     end
  89. end
  90.  
  91. main()
Add Comment
Please, Sign In to add comment