Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.85 KB | None | 0 0
  1. --cmatrix made by Wilma456
  2. --Licensed under BSD-2-Clause
  3. local component = require("component")
  4. local event = require("event")
  5. local thread = require("thread")
  6. local term = require("term")
  7. local gpu = component.gpu
  8.  
  9. local w,h = gpu.getResolution()
  10. local bBreak = false
  11. local nSpeed = 0.01
  12.  
  13. local tChars = {"1","2","3","4","5","6","7","8","9","0","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","(",")","!","?","[","]","{","}","/","\\","#","=","<",">","*",",",".","@","%"}
  14. local tLines = {}
  15. for i=1,w do
  16. if math.random(1,2) == 1 then
  17. tLines[i] = {true,math.random(1,10)}
  18. else
  19. tLines[i] = {false,math.random(1,10)}
  20. end
  21. end
  22.  
  23. local tText = {}
  24. for i=0,h do
  25. tText[i] = ""
  26. end
  27.  
  28. local function scrollDown()
  29. for i=h-1,1,-1 do
  30. gpu.copy(1,i,w,1,0,1)
  31. tText[i] = tText[i-1]
  32. end
  33. tText[h] = tText[h-1]
  34. tText[h+1] = nil
  35. end
  36.  
  37. local function generateText()
  38. local sText = ""
  39. for i=1,w do
  40. if tLines[i][1] == true then
  41. sText = sText..tChars[math.random(1,#tChars)]
  42. else
  43. sText = sText.." "
  44. end
  45. tLines[i][2] = tLines[i][2] - 1
  46. if tLines[i][2] == 0 then
  47. if math.random(1,2) == 1 then
  48. tLines[i] = {true,math.random(1,10)}
  49. else
  50. tLines[i] = {false,math.random(1,10)}
  51. end
  52. end
  53. end
  54. gpu.set(1,1,sText)
  55. tText[1] = sText
  56. end
  57.  
  58. local function redrawLines()
  59. --For cahnging Colours
  60. for i=1,h do
  61. if tText[i] == "" then
  62. gpu.set(1,i,"Test123")
  63. end
  64. gpu.set(1,i,tText[i])
  65. end
  66. end
  67.  
  68. gpu.setForeground(0x1ec503)
  69. gpu.setBackground(0x000000)
  70. gpu.fill(1, 1, w, h, " ")
  71.  
  72. generateText()
  73.  
  74. thread.create(function()
  75. while true do
  76. os.sleep(nSpeed)
  77. if bBreak == true then
  78. break
  79. end
  80. scrollDown()
  81. generateText()
  82. end
  83. end)
  84.  
  85. while true do
  86. local tEvent = table.pack(event.pull())
  87. if tEvent[1] == "key_down" then
  88. local sKey = string.upper(string.char(tEvent[3]))
  89. if sKey == "Q" then
  90. bBreak = true
  91. break
  92. elseif sKey == "0" then
  93. nSpeed = 0.01
  94. elseif sKey == "1" then
  95. nSpeed = 0.02
  96. elseif sKey == "2" then
  97. nSpeed = 0.03
  98. elseif sKey == "3" then
  99. nSpeed = 0.04
  100. elseif sKey == "4" then
  101. nSpeed = 0.05
  102. elseif sKey == "5" then
  103. nSpeed = 0.06
  104. elseif sKey == "6" then
  105. nSpeed = 0.07
  106. elseif sKey == "7" then
  107. nSpeed = 0.08
  108. elseif sKey == "8" then
  109. nSpeed = 0.09
  110. elseif sKey == "9" then
  111. nSpeed = 0.1
  112. elseif sKey == "@" then
  113. --Green
  114. gpu.setForeground(0x1ec503)
  115. redrawLines()
  116. elseif sKey == "!" then
  117. --Red
  118. gpu.setForeground(0xff0000)
  119. redrawLines()
  120. elseif sKey == "%" then
  121. --Magenta
  122. gpu.setForeground(0xff00ff)
  123. redrawLines()
  124. elseif sKey == "&" then
  125. --White
  126. gpu.setForeground(0xFFFFFF)
  127. redrawLines()
  128. elseif sKey == "$" then
  129. --Blue
  130. gpu.setForeground(0x0000ff)
  131. redrawLines()
  132. elseif sKey == "#" then
  133. --Yellow
  134. gpu.setForeground(0xffff00)
  135. redrawLines()
  136. elseif sKey == "^" then
  137. --Cyan
  138. gpu.setForeground(0x00ffff)
  139. redrawLines()
  140. end
  141. elseif tEvent[1] == "interrupted" then
  142. bBreak = true
  143. break
  144. end
  145. end
  146.  
  147. gpu.setForeground(0xFFFFFF)
  148. gpu.setBackground(0x000000)
  149. gpu.fill(1, 1, w, h, " ")
  150. term.setCursor(1,1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement