Advertisement
MigasRocha

Test Ascii Lua [CHAT GPT]

Apr 20th, 2024 (edited)
772
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.66 KB | None | 0 0
  1. -- Function to display styled text "Storage Room" on the monitor
  2. local function displayStyledTextOnMonitor(monitor)
  3.     monitor.setTextScale(2)  -- Set text scale to 2 for larger text
  4.     monitor.clear()  -- Clear the monitor screen
  5.  
  6.     local textToDisplay = "Storage Room"
  7.     local monitorWidth, monitorHeight = monitor.getSize()
  8.  
  9.     -- Set colors for text and background
  10.     monitor.setTextColor(colors.yellow)  -- Yellow text color
  11.     monitor.setBackgroundColor(colors.black)  -- Black background color
  12.  
  13.     -- Calculate starting coordinates to center text on the monitor
  14.     local textWidth = #textToDisplay * 8  -- Each character is 8 pixels wide at text scale 2
  15.     local startX = math.floor((monitorWidth - textWidth) / 2)
  16.     local startY = math.floor((monitorHeight - 2) / 2)  -- Center vertically
  17.  
  18.     -- Draw the styled text on the monitor
  19.     monitor.setCursorPos(startX, startY)
  20.     monitor.write(textToDisplay)
  21. end
  22.  
  23. -- Main function to interact with peripherals and display styled text on a monitor
  24. local function main()
  25.     -- List all connected peripherals
  26.     local peripherals = peripheral.getNames()
  27.  
  28.     -- Search for a monitor among connected peripherals
  29.     local monitor = nil
  30.     for _, name in ipairs(peripherals) do
  31.         if peripheral.getType(name) == "monitor" then
  32.             monitor = peripheral.wrap(name)
  33.             break
  34.         end
  35.     end
  36.  
  37.     -- Check if a monitor was found
  38.     if monitor then
  39.         print("Monitor found:", monitor)
  40.         displayStyledTextOnMonitor(monitor)  -- Display styled text on the monitor
  41.     else
  42.         print("No monitor found.")
  43.     end
  44. end
  45.  
  46. -- Run the main function
  47. main()
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement