Advertisement
_GameDoctor_

matrix

Mar 12th, 2020
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.47 KB | None | 0 0
  1. local event = require("event")
  2. local gpu = require("component").gpu
  3.  
  4. ------------------------------------------------------------------------------------------------------------
  5.  
  6. local maximumLines = 60
  7. local minimumLineLength = 5
  8. local maximumLineLength = 55
  9.  
  10. local chars = { "1", "0" }
  11. local lineColorsForeground = { 0xFFFFFF, 0xBBFFBB, 0x88FF88, 0x33FF33, 0x00FF00, 0x00EE00, 0x00DD00, 0x00CC00, 0x00BB00, 0x00AA00, 0x009900, 0x008800, 0x007700, 0x006600, 0x005500, 0x004400, 0x003300, 0x002200, 0x001100 }
  12. local lineColorsBackground = { 0x004400, 0x004400, 0x003300, 0x003300, 0x002200, 0x001100 }
  13.  
  14. local charsSize = #chars
  15. local lineColorsForegroundSize = #lineColorsForeground
  16.  
  17. ------------------------------------------------------------------------------------------------------------
  18.  
  19. local screenWidth, screenHeight = gpu.getResolution()
  20. local lines = {}
  21. local currentBackground, currentForeground
  22.  
  23. ------------------------------------------------------------------------------------------------------------
  24.  
  25. local function setBackground(color)
  26.     if currentBackground ~= color then
  27.         gpu.setBackground(color)
  28.         currentBackground = color
  29.     end
  30. end
  31.  
  32. local function setForeground(color)
  33.     if currentForeground ~= color then
  34.         gpu.setForeground(color)
  35.         currentForeground = color
  36.     end
  37. end
  38.  
  39. local function clearScreen()
  40.     setBackground(0x000000)
  41.     setForeground(0xFFFFFF)
  42.     gpu.fill(1, 1, screenWidth, screenHeight, " ")
  43. end
  44.  
  45. ------------------------------------------------------------------------------------------------------------
  46.  
  47. clearScreen()
  48.  
  49. local i, eventType, keyCode, part
  50. while true do
  51.     while #lines < maximumLines do
  52.         table.insert(lines, {
  53.             x = math.random(1, screenWidth),
  54.             y = 1,
  55.             length = math.random(minimumLineLength, maximumLineLength)
  56.         })
  57.     end
  58.  
  59.     gpu.copy(1, 1, screenWidth, screenHeight, 0, 1)
  60.     setBackground(0x000000)
  61.     gpu.fill(1, 1, screenWidth, 1, " ")
  62.  
  63.     i = 1
  64.     while i <= #lines do
  65.         if lines[i].y - lines[i].length <= 0 then
  66.             part = math.ceil(lineColorsForegroundSize * lines[i].y / lines[i].length)
  67.            
  68.             setForeground(lineColorsForeground[part] or 0x000000)
  69.             setBackground(lineColorsBackground[part] or 0x000000)
  70.             gpu.set(lines[i].x, 1, chars[math.random(1, charsSize)])
  71.  
  72.             i, lines[i].y = i + 1, lines[i].y + 1
  73.         else
  74.             table.remove(lines, i)
  75.         end
  76.     end
  77.  
  78.     eventType, _, _, keyCode = event.pull(0)
  79.     if eventType == "touch" or eventType == "key_down" and keyCode == 28 then
  80.         clearScreen()
  81.         break
  82.     end
  83. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement