SuicidalSTDz

[Lua]Matrix Code/Digital Rain

Mar 9th, 2013
1,602
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. term.setTextColor(colors.lime)
  2. local size={term.getSize()}
  3. local tPixels={}
  4. for x=1,size[1]-1 do
  5. tPixels[x]={}
  6. for y=1,size[2] do
  7. tPixels[x][y]=' '
  8. end
  9. end
  10. local function render()
  11. term.clear()
  12. term.setCursorPos(1,1)
  13. for y=1,#tPixels[1] do
  14. if y~=1 then
  15. print('')
  16. end
  17. for x=1,#tPixels do
  18. write(tPixels[x][y])
  19. end
  20. end
  21. end
  22. local function cycle()
  23. for x=1,#tPixels do
  24. for y=#tPixels[x],2,-1 do
  25. tPixels[x][y]=(tPixels[x][y-1]==' ' and ' ') or ((tPixels[x][y]~=' ' and tPixels[x][y]) or string.char(math.random(32,126)))
  26. end
  27. --[[for x=1,#tPixels do
  28. local intC=nil
  29. for y=2,5 do
  30. if tPixels[x][y]==' ' then
  31. intC=true
  32. end
  33. end
  34. if not intC then
  35. tPixels[x][1]=' '
  36. end
  37. end]]
  38. end
  39. end
  40. local function create()
  41. tPixels[math.random(1,#tPixels)][1]=string.char(math.random(32,126))
  42. tPixels[math.random(1,#tPixels)][1]=' '
  43. tPixels[math.random(1,#tPixels)][1]=' '
  44. end
  45. local bRunning=true
  46. while bRunning do
  47. cycle()
  48. create()
  49. render()
  50. local timer=os.startTimer(.1)
  51. while true do
  52. local sEvent, param = os.pullEvent()
  53. if (sEvent=='timer' and param==timer) then
  54. break
  55. end
  56. end
  57. end
Advertisement
Add Comment
Please, Sign In to add comment