Advertisement
Peileppe

matrix-effect.py

Apr 4th, 2014
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python
  2.  
  3. """
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11. GNU General Public License for more details.
  12. For a copy of the license see .
  13. =====================================================================
  14. Matrix Stream
  15. Sweeping of the screen surface and if column activated go for the next line
  16. on that column print a random character (could be space or bold)
  17. other possible options : curses.A_BLINK + curses.A_UNDERLINE + curses.A_STANDOUT
  18. while opening a new column etc ...
  19. =====================================================================
  20. Friday, April 04, 2014
  21. work (tested) with python 2.3 - 2.7
  22. www.peileppe.com
  23.  
  24. """
  25.  
  26. import curses
  27. import random
  28. import time
  29.  
  30. def print_randomcharacter_stream(xc,yl,ws,variation=0):
  31.     if variation==1:
  32.         char_stream=chr(random.randint(65,126))
  33.         ws.addch(yl,xc,char_stream, curses.A_BOLD)
  34.     elif variation==2:
  35.         ws.addch(yl,xc,' ')
  36.     else:
  37.         char_stream=chr(random.randint(32,126))
  38.         ws.addch(yl,xc,char_stream)
  39.     ws.move(0,0)
  40.     ws.refresh()
  41.     return
  42.  
  43. def main(self):
  44.     w=curses.initscr()
  45.     w.clear()
  46.     w.border()
  47.     w.keypad(1)
  48.     w.nodelay(1)
  49.     maxy, maxx =w.getmaxyx()
  50.    
  51.     action = ''
  52.     col_activated=[0]*(maxx-2)
  53.     flush_activated=[0]*(maxx-2)
  54.     xcol=0
  55.     generate_new=True
  56.    
  57.     while action != ord('q'):
  58.         while xcol <= maxx-3:
  59.             if col_activated[xcol] > 0:
  60.                 if col_activated[xcol] >= maxy-1:
  61.                     col_activated[xcol]=1
  62.                     generate_new=True
  63.                 if flush_activated[xcol] in range(51,65):
  64.                     print_randomcharacter_stream(xcol,col_activated[xcol],w,2)
  65.                 elif flush_activated[xcol] in range(25,50):
  66.                     print_randomcharacter_stream(xcol,col_activated[xcol],w,1)
  67.                 else:
  68.                     print_randomcharacter_stream(xcol,col_activated[xcol],w)
  69.                 flush_activated[xcol]+=1
  70.                 if flush_activated[xcol] > 65:
  71.                     flush_activated[xcol]=0
  72.                 col_activated[xcol]+=1
  73.             if generate_new :
  74.                 new_col=random.randint(1,maxx-3)
  75.                 col_activated[new_col]=1
  76.             xcol+=1
  77.             generate_new=False
  78.         xcol=0
  79.         action=w.getch()
  80.         time.sleep(0.1)
  81.     curses.endwin()
  82.  
  83. if __name__ == '__main__':                                                      
  84.     curses.wrapper(main)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement