Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Parametres configurables
- local bgColor = colors.black -- Couleur de fond
- local textColor = colors.green -- Couleur du texte
- local title = "Mekanism Energie Factory" -- Texte a afficher, '\n' pour retour a la ligne si besoin
- -- Initialisation du moniteur connecte automatiquement
- local mon = peripheral.find("monitor")
- if not mon then
- print("Aucun moniteur connecte n'a ete trouve.")
- return
- end
- -- Configuration du moniteur
- mon.setBackgroundColor(bgColor)
- mon.setTextColor(textColor)
- mon.clear()
- -- Fonction pour centrer et ajuster la taille du texte
- local function displayCenteredText(text)
- -- Diviser le texte en lignes selon les retours a la ligne
- local lines = {}
- for line in text:gmatch("([^\n]+)") do
- table.insert(lines, line)
- end
- -- Commencer avec l'echelle maximale et reduire jusqu'a ce que le texte tienne sur l'ecran
- local scale = 5.0
- while scale >= 0.5 do
- mon.setTextScale(scale)
- local width, height = mon.getSize()
- -- Verifier si le texte tient dans l'ecran actuel
- local textFits = true
- for _, line in ipairs(lines) do
- if #line > width then
- textFits = false
- break
- end
- end
- -- Si le texte tient dans les dimensions actuelles, arreter la boucle
- if textFits and #lines <= height then
- break
- else
- scale = scale - 0.1 -- Reduire l'echelle graduellement
- end
- end
- -- Calcul des positions pour centrer chaque ligne de texte
- local width, height = mon.getSize()
- local yStart = math.floor((height - #lines) / 2) + 1
- for i, line in ipairs(lines) do
- local xPos = math.floor((width - #line) / 2) + 1
- mon.setCursorPos(xPos, yStart + i - 1)
- mon.write(line)
- end
- end
- -- Affichage du texte centre
- displayCenteredText(title)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement