SHOW:
|
|
- or go back to the newest paste.
| 1 | - | #!/usr/local/bin/python |
| 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 | - | w=curses.initscr() |
| 18 | + | |
| 19 | - | w.clear() |
| 19 | + | |
| 20 | - | w.border() |
| 20 | + | Friday, April 04, 2014 |
| 21 | - | w.keypad(1) |
| 21 | + | |
| 22 | - | w.nodelay(1) |
| 22 | + | |
| 23 | - | maxy, maxx =w.getmaxyx() |
| 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 | - | action = '' |
| 38 | + | |
| 39 | - | col_activated=[0]*(maxx-2) |
| 39 | + | |
| 40 | - | flush_activated=[0]*(maxx-2) |
| 40 | + | |
| 41 | - | xcol=0 |
| 41 | + | |
| 42 | - | generate_new=True |
| 42 | + | |
| 43 | def main(self): | |
| 44 | - | while action != ord('q'):
|
| 44 | + | w=curses.initscr() |
| 45 | - | while xcol <= maxx-3: |
| 45 | + | w.clear() |
| 46 | - | if col_activated[xcol] > 0: |
| 46 | + | w.border() |
| 47 | - | if col_activated[xcol] >= maxy-1: |
| 47 | + | w.keypad(1) |
| 48 | - | col_activated[xcol]=1 |
| 48 | + | w.nodelay(1) |
| 49 | - | generate_new=True |
| 49 | + | maxy, maxx =w.getmaxyx() |
| 50 | - | if flush_activated[xcol] in range(51,65): |
| 50 | + | |
| 51 | - | print_randomcharacter_stream(xcol,col_activated[xcol],w,2) |
| 51 | + | action = '' |
| 52 | - | elif flush_activated[xcol] in range(25,50): |
| 52 | + | col_activated=[0]*(maxx-2) |
| 53 | - | print_randomcharacter_stream(xcol,col_activated[xcol],w,1) |
| 53 | + | flush_activated=[0]*(maxx-2) |
| 54 | - | else: |
| 54 | + | |
| 55 | - | print_randomcharacter_stream(xcol,col_activated[xcol],w) |
| 55 | + | generate_new=True |
| 56 | - | flush_activated[xcol]+=1 |
| 56 | + | |
| 57 | - | if flush_activated[xcol] > 65: |
| 57 | + | while action != ord('q'):
|
| 58 | - | flush_activated[xcol]=0 |
| 58 | + | while xcol <= maxx-3: |
| 59 | - | col_activated[xcol]+=1 |
| 59 | + | if col_activated[xcol] > 0: |
| 60 | - | if generate_new : |
| 60 | + | if col_activated[xcol] >= maxy-1: |
| 61 | - | new_col=random.randint(1,maxx-3) |
| 61 | + | col_activated[xcol]=1 |
| 62 | - | col_activated[new_col]=1 |
| 62 | + | generate_new=True |
| 63 | - | xcol+=1 |
| 63 | + | if flush_activated[xcol] in range(51,65): |
| 64 | - | generate_new=False |
| 64 | + | print_randomcharacter_stream(xcol,col_activated[xcol],w,2) |
| 65 | elif flush_activated[xcol] in range(25,50): | |
| 66 | - | action=w.getch() |
| 66 | + | print_randomcharacter_stream(xcol,col_activated[xcol],w,1) |
| 67 | - | time.sleep(0.1) |
| 67 | + | else: |
| 68 | - | curses.endwin() |
| 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) |