Advertisement
s3ptum

Scrolling txt Mega Inc

Sep 14th, 2013
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. mon = peripheral.wrap("back")
  2.  
  3. function lineBreak()
  4.  
  5. x, y = mon.getCursorPos()
  6.  
  7. if y ~= 1 then
  8.  
  9. y = y + 1
  10.  
  11. end
  12.  
  13. mon.setCursorPos(1, y)
  14.  
  15. width, height = mon.getSize()
  16.  
  17. mon.write(" " .. string.rep(" ", width - 2) .. " ")
  18.  
  19. end
  20.  
  21. function printString(sString)
  22.  
  23. x, y = mon.getCursorPos()
  24.  
  25. y = y + 1
  26.  
  27. mon.setCursorPos(1, y)
  28.  
  29. mon.write(sString)
  30.  
  31. end
  32.  
  33. function printStringCentre(sString)
  34.  
  35. x, y = mon.getCursorPos()
  36.  
  37. y = y + 1
  38.  
  39. mon.setCursorPos(1, y)
  40.  
  41. width, height = mon.getSize()
  42.  
  43. nStringCentre = math.floor(string.len(sString) / 2)
  44.  
  45. nMonitorCentre = math.floor(width / 2)
  46.  
  47. x = math.floor(nMonitorCentre - nStringCentre)
  48.  
  49. mon.setCursorPos(x, y)
  50.  
  51. mon.write(sString)
  52.  
  53. end
  54.  
  55. function printStringRight(sString)
  56.  
  57. width, height = mon.getSize()
  58.  
  59. x, y = mon.getCursorPos()
  60.  
  61. y = y + 1
  62.  
  63. x = math.ceil(width - string.len(sString))
  64.  
  65. mon.setCursorPos(x, y)
  66.  
  67. mon.write(sString)
  68.  
  69. end
  70.  
  71. function scrollText(tStrings, nRate)
  72.  
  73. nRate = nRate or 5
  74.  
  75. if nRate < 0 then
  76.  
  77. error("rate must be positive")
  78.  
  79. end
  80.  
  81. local nSleep = 1 / nRate
  82.  
  83.  
  84.  
  85. width, height = mon.getSize()
  86.  
  87. x, y = mon.getCursorPos()
  88.  
  89. sText = ""
  90.  
  91. for n = 1, #tStrings do
  92.  
  93. sText = sText .. tostring(tStrings[n])
  94.  
  95. sText = sText .. " | "
  96.  
  97. end
  98.  
  99. sString = "| "
  100.  
  101. if width / string.len(sText) < 1 then
  102.  
  103. nStringRepeat = 3
  104.  
  105. else
  106.  
  107. nStringRepeat = math.ceil(width / string.len(sText) * 3)
  108.  
  109. end
  110.  
  111. for n = 1, nStringRepeat do
  112.  
  113. sString = sString .. sText
  114.  
  115. end
  116.  
  117. while true do
  118.  
  119. for n = 1, string.len(sText) do
  120.  
  121. sDisplay = string.sub(sString, n, n + width - 1)
  122.  
  123. mon.clearLine()
  124.  
  125. mon.setCursorPos(1, y)
  126.  
  127. mon.write(sDisplay)
  128.  
  129. sleep(nSleep)
  130.  
  131. end
  132.  
  133. end
  134.  
  135. end
  136.  
  137. mon.clear()
  138.  
  139. mon.setCursorPos(1, 1)
  140.  
  141. lineBreak()
  142. mon.setTextColor(8)
  143. printStringCentre("Mega Inc.")
  144.  
  145. lineBreak()
  146.  
  147. printString("")
  148.  
  149. lineBreak()
  150. mon.setTextColor(2)
  151. tScrollText = {}
  152.  
  153. tScrollText[1] = "Grand Reopening!!!"
  154.  
  155. tScrollText[2] = "New! Certus Quartz Trading!"
  156.  
  157. x, y = mon.getCursorPos()
  158.  
  159. y = y - 1
  160.  
  161. mon.setCursorPos(1, y)
  162.  
  163. scrollText(tScrollText)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement