Advertisement
devomaa

s

Mar 8th, 2020
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1.  
  2. in:
  3. Lua, Computer craft, Coding, and 4 more
  4. LUA Vertical Scroller
  5. Edit
  6. Comments
  7.  
  8.  
  9. Simple Vertical Scroller Computer Craft This is a very simple vertical Scroller in LUA.
  10.  
  11. It runs an infinate loop that can be stopped by pressing [END] key on your keyboard. It will read the text to be displayed from a file called text.txt in the same folder. Complete CODE
  12.  
  13. tSides = {"left","right","bottom","top","front","back"}
  14.  
  15. for i = 1, #tSides do
  16. monitor = peripheral.wrap(tSides[i])
  17. if monitor then
  18. side = tSides[i]
  19. break
  20. end
  21. end
  22.  
  23. term.redirect(peripheral.wrap(side))
  24. term.clear()
  25. term.setCursorPos(1,1)
  26. local data = {}
  27. local breakOut = false
  28. logo = [[
  29.  
  30. ____ ____ ____ _____ _ _ _ _
  31. | _ \| _ \ / ___|_ _|__| | _| | _(_) |_
  32. | |_) | |_) | | _ | |/ _ \ |/ / |/ / | __|
  33. | _ <| __/| |_| | | | __/ <| <| | |_
  34. |_| \_\_| \____| |_|\___|_|\_\_|\_\_|\__|
  35.  
  36. ]]
  37.  
  38. function clearscreen()
  39. local _,row=term.getCursorPos()
  40. local _,height=term.getSize()
  41. width, height = term.getSize()
  42. term.setCursorPos(1,1)
  43. dl = ""
  44. sl = ""
  45. for g=1,width do
  46. dl =dl.."_"
  47. sl = sl.." "
  48. end
  49. for y=1,height do
  50. term.setCursorPos(1,y)
  51. print(dl)
  52. sleep(0.01)
  53. end
  54.  
  55. for y=1,height do
  56. term.setCursorPos(1,y)
  57. print(sl)
  58. sleep(0.01)
  59. end
  60. term.clear()
  61. end
  62.  
  63. function printTo()
  64. local _,row=term.getCursorPos()
  65. local _,height=term.getSize()
  66. term.setCursorPos(1,1)
  67. print(logo)
  68. term.setCursorPos(1,8)
  69. row = 8
  70. for i=1,#data do
  71. print(data[i])
  72. sleep(1)
  73. row=row+1
  74. if row>height then
  75. row=height
  76. term.scroll(1)
  77. end
  78. end
  79. end
  80.  
  81. local function readLines(sPath)
  82. local file = fs.open(sPath, "r")
  83. local line = file.readLine()
  84. local lineNum = 0
  85.  
  86. while line do
  87. table.insert(data, line)
  88. line = file.readLine()
  89. lineNum = lineNum + 1
  90. end
  91. file.close()
  92. sleep(1)
  93. end
  94.  
  95. function newLine()
  96. local _,cY= term.getCursorPos()
  97. term.setCursorPos(1,cY+1)
  98. end
  99.  
  100. function program()
  101. while true do
  102. clearscreen()
  103. printTo()
  104. sleep(0.5)
  105. end
  106. end
  107.  
  108. function exitProgram()
  109. repeat
  110. local ev, key = os.pullEvent('key')
  111. until key == 207
  112. end
  113. readLines("text.txt")
  114. parallel.waitForAny(program, exitProgram)
  115. term.restore()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement