Created
July 13, 2011 13:45
-
-
Save melissaboiko/1080314 to your computer and use it in GitHub Desktop.
simple matrix-style demo. done out of nostalgia for what it was like to study linux in the 90s.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import locale | |
import curses as c | |
from curses.wrapper import wrapper | |
import random | |
locale.setlocale(locale.LC_ALL,'') | |
coding = locale.getpreferredencoding() | |
random.seed() | |
# more = use digits more often | |
digits_weight = 0.6 | |
spaces_weight = 0.8 | |
bold_weight = 0.5 | |
katakana = range(0xff66, 0xff9d) | |
digits = range(0x0030, 0x0039) | |
katakana = map(lambda cp: unichr(cp).encode(coding), | |
katakana) | |
digits = map(lambda cp: unichr(cp).encode(coding), | |
digits) | |
def a_char(): | |
if random.random() <= digits_weight: | |
return random.choice(digits) | |
else: | |
return random.choice(katakana) | |
def main(w): | |
c.init_pair(1, c.COLOR_GREEN, c.COLOR_BLACK) | |
attr = c.color_pair(1) | |
miny, minx = w.getbegyx() | |
maxy, maxx = w.getmaxyx() | |
while 1: | |
if random.random() <= spaces_weight: | |
char = ' ' | |
else: | |
char = a_char() | |
if random.random() <= bold_weight: | |
attr |= c.A_BOLD | |
else: | |
attr ^= c.A_BOLD | |
y = random.choice(range(miny, maxy-1)) | |
x = random.choice(range(minx, maxx-1)) | |
w.move(y,x) | |
w.addstr(char, attr) | |
w.refresh() | |
wrapper(main) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment