Created
December 24, 2012 06:11
Revisions
-
davea revised this gist
Dec 22, 2011 . 1 changed file with 11 additions and 6 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -75,13 +75,19 @@ def get_random_flake(): return " *" def get_flake_column(): return [1, get_random_flake(), random.choice(range(1, 4)), 0] def move_flake(col): if snowflakes[col][0]+1 == rows: snowflakes[col] = get_flake_column() else: print("\033[%s;%sH " % (snowflakes[col][0], col)) snowflakes[col][3] += 1 snowflakes[col][3] %= snowflakes[col][2] if snowflakes[col][3] == 0: snowflakes[col][0] += 1 print("\033[%s;%sH%s" % (snowflakes[col][0], col, snowflakes[col][1])) @@ -99,8 +105,7 @@ def move_flake(col): move_flake(col) else: # otherwise put it on the screen snowflakes[col] = get_flake_column() print("\033[%s;%sH%s" % (snowflakes[col][0], col, snowflakes[col][1])) @@ -109,4 +114,4 @@ def move_flake(col): for flake in snowflakes.keys(): move_flake(flake) time.sleep(0.025) -
sontek revised this gist
Dec 22, 2011 . 1 changed file with 15 additions and 15 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -13,21 +13,6 @@ except ImportError: pass def get_terminal_size(): def ioctl_GWINSZ(fd): try: @@ -58,6 +43,21 @@ def ioctl_GWINSZ(fd): columns, rows = get_terminal_size() def clear_screen(numlines=100): """Clear the console. numlines is an optional argument used only as a fall-back. """ if os.name == "posix": # Unix/Linux/MacOS/BSD/etc os.system('clear') elif os.name in ("nt", "dos", "ce"): # DOS/Windows os.system('cls') else: # Fallback for other operating systems. print('\n' * rows) def get_random_flake(): if not platform.system() == 'Windows': try: -
sontek revised this gist
Dec 22, 2011 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import os import random import time import platform snowflakes = {} @@ -58,7 +59,7 @@ def ioctl_GWINSZ(fd): columns, rows = get_terminal_size() def get_random_flake(): if not platform.system() == 'Windows': try: # python3 support try: -
sontek revised this gist
Dec 22, 2011 . 1 changed file with 12 additions and 9 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -58,18 +58,21 @@ def ioctl_GWINSZ(fd): columns, rows = get_terminal_size() def get_random_flake(): if os.name == "posix": try: # python3 support try: cmd = unichr except NameError: cmd = chr flake = cmd(random.choice(range(0x2740, 0x2749))) return flake except: pass return " *" def move_flake(col): if snowflakes[col][0]+1 == rows: -
sontek revised this gist
Dec 22, 2011 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -69,13 +69,13 @@ def get_random_flake(): return flake except: return " *" def move_flake(col): if snowflakes[col][0]+1 == rows: snowflakes[col] = [1, get_random_flake()] else: print("\033[%s;%sH " % (snowflakes[col][0], col)) snowflakes[col][0] += 1 -
sontek revised this gist
Dec 22, 2011 . 1 changed file with 7 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -5,6 +5,13 @@ snowflakes = {} try: # Windows Support from colorama import init init() except ImportError: pass def clear_screen(numlines=100): """Clear the console. -
sontek revised this gist
Dec 22, 2011 . 1 changed file with 26 additions and 8 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -5,6 +5,21 @@ snowflakes = {} def clear_screen(numlines=100): """Clear the console. numlines is an optional argument used only as a fall-back. """ if os.name == "posix": # Unix/Linux/MacOS/BSD/etc os.system('clear') elif os.name in ("nt", "dos", "ce"): # DOS/Windows os.system('cls') else: # Fallback for other operating systems. print('\n' * numlines) def get_terminal_size(): def ioctl_GWINSZ(fd): try: @@ -36,16 +51,18 @@ def ioctl_GWINSZ(fd): columns, rows = get_terminal_size() def get_random_flake(): try: # python3 support try: cmd = unichr except NameError: cmd = chr flake = cmd(random.choice(range(0x2740, 0x2749))) return flake except: return "*" def move_flake(col): if snowflakes[col][0]+1 == rows: @@ -60,7 +77,8 @@ def move_flake(col): print("\033[1;1H") if __name__ == "__main__": clear_screen() while True: col = random.choice(range(1, int(columns))) -
sontek revised this gist
Dec 22, 2011 . 1 changed file with 17 additions and 7 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -16,7 +16,9 @@ def ioctl_GWINSZ(fd): except: return None return cr cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2) if not cr: try: fd = os.open(os.ctermid(), os.O_RDONLY) @@ -34,20 +36,28 @@ def ioctl_GWINSZ(fd): columns, rows = get_terminal_size() def get_random_flake(): # python3 support try: cmd = unichr except NameError: cmd = chr flake = cmd(random.choice(range(0x2740, 0x2749))) return flake def move_flake(col): if snowflakes[col][0]+1 == rows: snowflakes[col] = [1, get_random_flake()] else: print("\033[%s;%sH " % (snowflakes[col][0], col)) snowflakes[col][0] += 1 print("\033[%s;%sH%s" % (snowflakes[col][0], col, snowflakes[col][1])) print("\033[1;1H") if __name__ == "__main__": os.system('clear') @@ -63,8 +73,8 @@ def move_flake(col): flake = get_random_flake() snowflakes[col] = [1, flake] print("\033[%s;%sH%s" % (snowflakes[col][0], col, snowflakes[col][1])) # key any flakes on the screen moving for flake in snowflakes.keys(): -
sontek revised this gist
Dec 22, 2011 . 1 changed file with 54 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,16 @@ #!/usr/bin/env python import os import random import time snowflakes = {} def get_terminal_size(): def ioctl_GWINSZ(fd): try: import fcntl import termios import struct cr = struct.unpack('hh', fcntl.ioctl(fd, termios.TIOCGWINSZ, '1234')) except: @@ -17,7 +26,48 @@ def ioctl_GWINSZ(fd): pass if not cr: try: cr = (os.environ['LINES'], os.environ['COLUMNS']) except: cr = (25, 80) return int(cr[1]), int(cr[0]) columns, rows = get_terminal_size() def get_random_flake(): flake=unichr(random.choice(range(0x2740, 0x2749))) return flake def move_flake(col): if snowflakes[col][0]+1 == rows: snowflakes[col] = [1, get_random_flake()] else: print "\033[%s;%sH " % (snowflakes[col][0], col) snowflakes[col][0] += 1 print u"\033[%s;%sH%s" % (snowflakes[col][0], col, snowflakes[col][1]) print "\033[1;1H" if __name__ == "__main__": os.system('clear') while True: col = random.choice(range(1, int(columns))) # its already on the screen, move it if col in snowflakes.keys(): move_flake(col) else: # otherwise put it on the screen flake = get_random_flake() snowflakes[col] = [1, flake] print "\033[%s;%sH%s" % (snowflakes[col][0], col, snowflakes[col][1]) # key any flakes on the screen moving for flake in snowflakes.keys(): move_flake(flake) time.sleep(0.1) -
sontek revised this gist
Dec 22, 2011 . No changes.There are no files selected for viewing
-
sontek revised this gist
Dec 22, 2011 . 1 changed file with 23 additions and 45 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,45 +1,23 @@ def getTerminalSize(): def ioctl_GWINSZ(fd): try: import fcntl, termios, struct, os cr = struct.unpack('hh', fcntl.ioctl(fd, termios.TIOCGWINSZ, '1234')) except: return None return cr cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2) if not cr: try: fd = os.open(os.ctermid(), os.O_RDONLY) cr = ioctl_GWINSZ(fd) os.close(fd) except: pass if not cr: try: cr = (env['LINES'], env['COLUMNS']) except: cr = (25, 80) return int(cr[1]), int(cr[0]) -
sontek revised this gist
Dec 22, 2011 . 1 changed file with 17 additions and 9 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -5,15 +5,20 @@ snowflakes = {} rows, columns = map(int, os.popen('stty size', 'r').read().split()) def get_random_flake(): flake=unichr(random.choice(range(0x2740, 0x2749))) return flake def move_flake(col): if snowflakes[col][0]+1 == rows: snowflakes[col] = [1, get_random_flake()] else: print "\033[%s;%sH " % (snowflakes[col][0], col) snowflakes[col][0] += 1 print u"\033[%s;%sH%s" % (snowflakes[col][0], col, snowflakes[col][1]) print "\033[1;1H" if __name__ == "__main__": @@ -27,10 +32,13 @@ def move_flake(col): move_flake(col) else: # otherwise put it on the screen flake = get_random_flake() snowflakes[col] = [1, flake] print "\033[%s;%sH%s" % (snowflakes[col][0], col, snowflakes[col][1]) # key any flakes on the screen moving for flake in snowflakes.keys(): move_flake(flake) -
sontek revised this gist
Dec 22, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -30,7 +30,7 @@ def move_flake(col): snowflakes[col] = 1 print "\033[%s;%sH*" % (snowflakes[col], col) # keep any flakes on the screen moving for flake in snowflakes.keys(): move_flake(flake) -
sontek created this gist
Dec 22, 2011 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,37 @@ #!/usr/bin/env python import os import random import time snowflakes = {} rows, columns = map(int, os.popen('stty size', 'r').read().split()) def move_flake(col): if snowflakes[col]+1 == rows: snowflakes[col] = 1 else: print "\033[%s;%sH " % (snowflakes[col], col) snowflakes[col] += 1 print "\033[%s;%sH*" % (snowflakes[col], col) print "\033[1;1H" if __name__ == "__main__": os.system('clear') while True: col = random.choice(range(1, int(columns))) # its already on the screen, move it if col in snowflakes.keys(): move_flake(col) else: # otherwise put it on the screen snowflakes[col] = 1 print "\033[%s;%sH*" % (snowflakes[col], col) # key any flakes on the screen moving for flake in snowflakes.keys(): move_flake(flake) time.sleep(0.1)