Peileppe

matrix-screen

Mar 28th, 2014
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.90 KB | None | 0 0
  1. #!/usr/local/bin/python
  2.  
  3. """
  4. Matrix Stream
  5. Sweeping of the screen surface and if column activated go for the next line
  6. on that column print a random character (could be space or bold)
  7. while opening a new column etc ...
  8. =====================================================================
  9. work (tested) with python 2.3 - 2.7
  10. www.peileppe.com
  11.  
  12. """
  13.  
  14. import curses
  15. import random
  16. import time
  17.  
  18. w=curses.initscr()
  19. w.clear()
  20. w.border()
  21. w.keypad(1)
  22. w.nodelay(1)
  23. maxy, maxx =w.getmaxyx()
  24.  
  25. def print_randomcharacter_stream(xc,yl,ws,variation=0):
  26.     if variation==1:
  27.         char_stream=chr(random.randint(65,126))
  28.         ws.addch(yl,xc,char_stream, curses.A_BOLD)
  29.     elif variation==2:
  30.         ws.addch(yl,xc,' ')
  31.     else:
  32.         char_stream=chr(random.randint(32,126))
  33.         ws.addch(yl,xc,char_stream)
  34.     ws.move(0,0)
  35.     ws.refresh()
  36.     return
  37.  
  38. action = ''
  39. col_activated=[0]*(maxx-2)
  40. flush_activated=[0]*(maxx-2)
  41. xcol=0
  42. generate_new=True
  43.  
  44. while action != ord('q'):
  45.     while xcol <= maxx-3:
  46.         if col_activated[xcol] > 0:
  47.             if col_activated[xcol] >= maxy-1:
  48.                 col_activated[xcol]=1
  49.                 generate_new=True
  50.             if flush_activated[xcol] in range(51,65):
  51.                 print_randomcharacter_stream(xcol,col_activated[xcol],w,2)
  52.             elif flush_activated[xcol] in range(25,50):
  53.                 print_randomcharacter_stream(xcol,col_activated[xcol],w,1)
  54.             else:
  55.                 print_randomcharacter_stream(xcol,col_activated[xcol],w)
  56.             flush_activated[xcol]+=1
  57.             if flush_activated[xcol] > 65:
  58.                 flush_activated[xcol]=0
  59.             col_activated[xcol]+=1
  60.         if generate_new :
  61.             new_col=random.randint(1,maxx-3)
  62.             col_activated[new_col]=1
  63.         xcol+=1
  64.         generate_new=False
  65.     xcol=0
  66.     action=w.getch()
  67.     time.sleep(0.1)
  68. curses.endwin()
Advertisement
Add Comment
Please, Sign In to add comment