Achman741

Matrix Screen Saver CC

Nov 8th, 2013
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.04 KB | None | 0 0
  1. --Achman741 Borrowed This
  2. --I claim no credit for this
  3.  
  4. --[[
  5. File: matrix
  6. Purpose: A screensaver that emulates screens from the popular movie The Matrix. *A component of TurtleSHELL*
  7. Author: da404lewzer
  8. Project: http://turtlescripts.com/project/gjdh00
  9. License: Creative Commons Attribution-ShareAlike 3.0 Unported License.
  10. http://creativecommons.org/licenses/by-sa/3.0/
  11.  
  12. Changes:
  13. 1.0.10 12/10/2012
  14. + Detached to seperate project
  15.  
  16. 1.0.0 11/27/2012
  17. * Cloned file from texty
  18. ]]
  19.  
  20. --User settings (Overridden by texty.settings if file is found)
  21. local largeFont = 0.5
  22. local smallFont = 0.5
  23. --App-managed variables:
  24. local tArgs = { ... }
  25. local mon
  26. local w, h = 1,1
  27. local ss_running = true
  28. local positions = {"top", "bottom", "left", "right", "front", "back"}
  29. local mons = {}
  30. local curMsg = {}
  31. local curColor = {}
  32.  
  33. local skipMove = 1
  34. function getColorMode(monitor)
  35. if monitor.isColor() then
  36. return 2
  37. else
  38. return 1
  39. end
  40. end
  41. local chars = {"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","0","1","2","3","4","5","6","7","8","9", "@", "#", "$", "%", "&", "?", "!", "*"}
  42.  
  43. function regen(monID, c)
  44. len = math.random(2,h/2)
  45. mons[monID].cols[c] = {length=len, x=c, y=-math.random(1,len), speed=math.random(1,3)}
  46. end
  47. function update(monitor, monID)
  48. mon = monitor
  49.  
  50. --if mon then
  51. w, h = mon.getSize()
  52. --mon.clear()
  53. mon.setBackgroundColor(colors.black)
  54. for c=1, w do
  55. if mons[monID] then
  56. col = mons[monID].cols[c]
  57. if col then
  58. local x, y, i, flicker
  59. local colorMode = getColorMode(mon)
  60. mon.setTextColor(colors.white)
  61. --tX[monID] = 2
  62. --tY[monID] = 2
  63. for ii=col.length, 1, -1 do
  64. flicker = math.random(1, 3)
  65. if colorMode == 1 then
  66. mon.setTextColor(colors.black)
  67. else
  68. mon.setTextColor(colors.green)
  69. end
  70. local iii = -col.length
  71. local msgText = chars[math.random(#chars)]
  72. if math.random(2)==1 then
  73. msgText = string.upper(msgText)
  74. end
  75. mon.setCursorPos(col.x, col.y-ii)
  76. mon.write(msgText)
  77. end
  78. flicker = math.random(1, 3)
  79. if colorMode == 1 then
  80. if flicker == 1 then
  81. mon.setTextColor(colors.black)
  82. else
  83. mon.setTextColor(colors.white)
  84. end
  85. else
  86. if flicker == 1 then
  87. mon.setTextColor(colors.lime)
  88. elseif flicker == 2 then
  89. mon.setTextColor(colors.white)
  90. elseif flicker == 3 then
  91. mon.setTextColor(colors.green)
  92. end
  93. end
  94. local msgText = chars[math.random(#chars)]
  95. if math.random(2)==1 then
  96. msgText = string.upper(msgText)
  97. end
  98. mon.setCursorPos(col.x, col.y)
  99. mon.write(msgText)
  100. mon.setTextColor(colors.black)
  101. for ii=0,col.speed do
  102. mon.setCursorPos(col.x, col.y-col.length-col.speed+ii)
  103. mon.write(" ")
  104. end
  105. if skipMove==0 then
  106. col.y=col.y+col.speed
  107. if col.y - col.length - col.speed > h then
  108. regen(monID, c)
  109. end
  110. end
  111. else
  112. regen(monID, c)
  113. end
  114. else
  115. regen(monID, c)
  116. end
  117. end
  118. --end
  119. end
  120. function updateTemplate(monitor, monID)
  121. if monitor then
  122. w,h = monitor.getSize()
  123. if w and h then
  124. if not mons[monID] then
  125. --[[if monitor ~= term then
  126. if w > 7 and h > 5 then
  127. monitor.setTextScale(largeFont)
  128. else
  129. monitor.setTextScale(smallFont)
  130. end
  131. w,h = monitor.getSize()
  132. end]]
  133. for c=1, w do
  134. mons[monID] = {cols={}}
  135. regen(monID, c)
  136. end
  137. end
  138. update(monitor, monID)
  139. end
  140. end
  141. end
  142. function updateAll()
  143. updateTemplate(term, 0)
  144. for i=1, #positions do
  145. if peripheral.getType(positions[i]) == "monitor" then
  146. updateTemplate(peripheral.wrap(positions[i]), i)
  147. end
  148. end
  149. end
  150. function cleanUp()
  151. term.clear()
  152. term.setCursorPos(1,1)
  153. for i=1, #positions do
  154. if peripheral.getType(positions[i]) == "monitor" then
  155. local mon = peripheral.wrap(positions[i])
  156. if mon then
  157. mon.setTextScale(1)
  158. mon.clear()
  159. mon.setCursorPos(1,1)
  160. end
  161. end
  162. end
  163. end
  164. local ss_timer = os.startTimer(0)
  165. while ss_running do
  166. local event, p1, p2 = os.pullEvent()
  167. if event == "key" then
  168. ss_running = false
  169. else
  170. if event == "timer" and p1 == ss_timer then
  171. ss_timer = os.startTimer(0.05)
  172. end
  173. if ss_running then
  174. updateAll()
  175. skipMove = skipMove + 1
  176. if skipMove > 5 then
  177. skipMove = 0
  178. end
  179. end
  180. end
  181. end
  182.  
  183. cleanUp()
Advertisement
Add Comment
Please, Sign In to add comment