Advertisement
Steamer1

Text scrolling

Jan 28th, 2020
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.17 KB | None | 0 0
  1. local mon = peripheral.find("monitor")
  2. mon.clear()
  3. mon.setCursorPos(3,2)
  4. mon.setTextScale(5)
  5. mon.setBackgroundColor(colors.black)
  6.  
  7. function scrollText(tStrings, nRate)
  8. nRate = nRate or 5
  9. if nRate < 0 then
  10.   error("rate must be positive")
  11. end
  12. local nSleep = 1 / nRate
  13.  
  14. width, height = mon.getSize()
  15. x, y = mon.getCursorPos()
  16.         sText = ""
  17.         for n = 1, #tStrings do
  18.                 sText = sText .. tostring(tStrings[n])
  19.   sText = sText .. " | "
  20.         end
  21.         sString = "| "
  22.         if width / string.len(sText) < 1 then
  23.                 nStringRepeat = 3
  24.         else
  25.                 nStringRepeat = math.ceil(width / string.len(sText) * 3)
  26.         end
  27. for n = 1, nStringRepeat do
  28.   sString = sString .. sText
  29. end
  30. while true do
  31.   for n = 1, string.len(sText) do
  32.    sDisplay = string.sub(sString, n, n + width - 1)
  33.    mon.clearLine()
  34.    mon.setCursorPos(1, y)
  35.    mon.setBackgroundColor(colors.lightGray)
  36.    mon.write(sDisplay)
  37.    mon.setBackgroundColor(colors.black)
  38.    sleep(nSleep)
  39.   end
  40. end
  41. end
  42.  
  43. mon.write("Attention")
  44. mon.setCursorPos(4,6)
  45. mon.write("DANGER")
  46. mon.setCursorPos(1,4)
  47. scrollText({"Industrial Craft","Centre de test"},3)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement