Advertisement
N2AZ

clock

Aug 12th, 2024 (edited)
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.24 KB | None | 0 0
  1. local m = peripheral.find("monitor")
  2. term.redirect(m)
  3. term.clear()
  4. m.setTextColour(colors.yellow)
  5. m.setBackgroundColour(colors.black)
  6.  
  7. -- Définir une échelle fixe
  8. m.setTextScale(5)
  9.  
  10. -- Function to get weather
  11. local function getWeather()
  12.     local success, weather = commands.exec("weather query")
  13.     if success then
  14.         if weather:find("rain") then
  15.             return "rainy"
  16.         elseif weather:find("thunder") then
  17.             return "thunder"
  18.         else
  19.             return "sunny"
  20.         end
  21.     end
  22.     return "???"
  23. end
  24.  
  25. -- Function to center text on the monitor
  26. local function centerText(text, line)
  27.     local w, h = term.getSize()
  28.     local x = math.floor((w - #text) / 2) + 1
  29.     return x, line
  30. end
  31.  
  32. -- Main loop
  33. while true do
  34.     term.clear()
  35.    
  36.     -- Affichage de l'heure
  37.     local time = os.time()
  38.     local formattedTime = textutils.formatTime(time, true)
  39.    
  40.     local x, y = centerText(formattedTime, math.floor(h / 2))
  41.     term.setCursorPos(x, y)
  42.     term.write(formattedTime)
  43.    
  44.     -- Affichage de la météo
  45.     local weather = getWeather()
  46.     local wx, wy = centerText(weather, math.floor(h / 2) + 2)
  47.     term.setCursorPos(wx, wy)
  48.     term.write(weather)
  49.    
  50.     os.sleep(0.5)
  51. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement