Advertisement
BigBlow_

Ecran Titre

Nov 11th, 2024 (edited)
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. -- Parametres configurables
  2. local bgColor = colors.black -- Couleur de fond
  3. local textColor = colors.green -- Couleur du texte
  4. local title = "Mekanism Energie Factory" -- Texte a afficher, '\n' pour retour a la ligne si besoin
  5.  
  6. -- Initialisation du moniteur connecte automatiquement
  7. local mon = peripheral.find("monitor")
  8. if not mon then
  9. print("Aucun moniteur connecte n'a ete trouve.")
  10. return
  11. end
  12.  
  13. -- Configuration du moniteur
  14. mon.setBackgroundColor(bgColor)
  15. mon.setTextColor(textColor)
  16. mon.clear()
  17.  
  18. -- Fonction pour centrer et ajuster la taille du texte
  19. local function displayCenteredText(text)
  20. -- Diviser le texte en lignes selon les retours a la ligne
  21. local lines = {}
  22. for line in text:gmatch("([^\n]+)") do
  23. table.insert(lines, line)
  24. end
  25.  
  26. -- Commencer avec l'echelle maximale et reduire jusqu'a ce que le texte tienne sur l'ecran
  27. local scale = 5.0
  28. while scale >= 0.5 do
  29. mon.setTextScale(scale)
  30.  
  31. local width, height = mon.getSize()
  32.  
  33. -- Verifier si le texte tient dans l'ecran actuel
  34. local textFits = true
  35. for _, line in ipairs(lines) do
  36. if #line > width then
  37. textFits = false
  38. break
  39. end
  40. end
  41.  
  42. -- Si le texte tient dans les dimensions actuelles, arreter la boucle
  43. if textFits and #lines <= height then
  44. break
  45. else
  46. scale = scale - 0.1 -- Reduire l'echelle graduellement
  47. end
  48. end
  49.  
  50. -- Calcul des positions pour centrer chaque ligne de texte
  51. local width, height = mon.getSize()
  52. local yStart = math.floor((height - #lines) / 2) + 1
  53. for i, line in ipairs(lines) do
  54. local xPos = math.floor((width - #line) / 2) + 1
  55. mon.setCursorPos(xPos, yStart + i - 1)
  56. mon.write(line)
  57. end
  58. end
  59.  
  60. -- Affichage du texte centre
  61. displayCenteredText(title)
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement