Skip to content

Instantly share code, notes, and snippets.

@joshkehn
Created December 24, 2012 06:11

Revisions

  1. @davea davea revised this gist Dec 22, 2011. 1 changed file with 11 additions and 6 deletions.
    17 changes: 11 additions & 6 deletions snowjob.py
    Original 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] = [1, get_random_flake()]
    snowflakes[col] = get_flake_column()
    else:
    print("\033[%s;%sH " % (snowflakes[col][0], col))

    snowflakes[col][0] += 1

    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
    flake = get_random_flake()
    snowflakes[col] = [1, flake]
    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.1)
    time.sleep(0.025)
  2. @sontek sontek revised this gist Dec 22, 2011. 1 changed file with 15 additions and 15 deletions.
    30 changes: 15 additions & 15 deletions snowjob.py
    Original file line number Diff line number Diff line change
    @@ -13,21 +13,6 @@
    except ImportError:
    pass

    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:
    @@ -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:
  3. @sontek sontek revised this gist Dec 22, 2011. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion snowjob.py
    Original 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 os.name == "posix":
    if not platform.system() == 'Windows':
    try:
    # python3 support
    try:
  4. @sontek sontek revised this gist Dec 22, 2011. 1 changed file with 12 additions and 9 deletions.
    21 changes: 12 additions & 9 deletions snowjob.py
    Original 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():
    try:
    # python3 support
    if os.name == "posix":
    try:
    cmd = unichr
    except NameError:
    cmd = chr
    # python3 support
    try:
    cmd = unichr
    except NameError:
    cmd = chr

    flake = cmd(random.choice(range(0x2740, 0x2749)))
    flake = cmd(random.choice(range(0x2740, 0x2749)))

    return flake
    except:
    return " *"
    return flake
    except:
    pass

    return " *"

    def move_flake(col):
    if snowflakes[col][0]+1 == rows:
  5. @sontek sontek revised this gist Dec 22, 2011. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions snowjob.py
    Original file line number Diff line number Diff line change
    @@ -69,13 +69,13 @@ def get_random_flake():

    return flake
    except:
    return "*"
    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))
    print("\033[%s;%sH " % (snowflakes[col][0], col))

    snowflakes[col][0] += 1

  6. @sontek sontek revised this gist Dec 22, 2011. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions snowjob.py
    Original 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.
  7. @sontek sontek revised this gist Dec 22, 2011. 1 changed file with 26 additions and 8 deletions.
    34 changes: 26 additions & 8 deletions snowjob.py
    Original 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():
    # python3 support
    try:
    cmd = unichr
    except NameError:
    cmd = chr

    flake = cmd(random.choice(range(0x2740, 0x2749)))
    # python3 support
    try:
    cmd = unichr
    except NameError:
    cmd = chr

    return flake
    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__":
    os.system('clear')

    clear_screen()

    while True:
    col = random.choice(range(1, int(columns)))
  8. @sontek sontek revised this gist Dec 22, 2011. 1 changed file with 17 additions and 7 deletions.
    24 changes: 17 additions & 7 deletions snowjob.py
    Original 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():
    flake=unichr(random.choice(range(0x2740, 0x2749)))
    # 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)
    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"

    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])
    print("\033[%s;%sH%s" % (snowflakes[col][0], col,
    snowflakes[col][1]))

    # key any flakes on the screen moving
    for flake in snowflakes.keys():
  9. @sontek sontek revised this gist Dec 22, 2011. 1 changed file with 54 additions and 4 deletions.
    58 changes: 54 additions & 4 deletions snowjob.py
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,16 @@
    def getTerminalSize():
    #!/usr/bin/env python
    import os
    import random
    import time

    snowflakes = {}

    def get_terminal_size():
    def ioctl_GWINSZ(fd):
    try:
    import fcntl, termios, struct, os
    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 = (env['LINES'], env['COLUMNS'])
    cr = (os.environ['LINES'], os.environ['COLUMNS'])
    except:
    cr = (25, 80)
    return int(cr[1]), int(cr[0])
    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)
  10. @sontek sontek revised this gist Dec 22, 2011. No changes.
  11. @sontek sontek revised this gist Dec 22, 2011. 1 changed file with 23 additions and 45 deletions.
    68 changes: 23 additions & 45 deletions snowjob.py
    Original file line number Diff line number Diff line change
    @@ -1,45 +1,23 @@
    #!/usr/bin/env python
    import os
    import random
    import time

    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__":
    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)
    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])
  12. @sontek sontek revised this gist Dec 22, 2011. 1 changed file with 17 additions and 9 deletions.
    26 changes: 17 additions & 9 deletions snowjob.py
    Original 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]+1 == rows:
    snowflakes[col] = 1
    if snowflakes[col][0]+1 == rows:
    snowflakes[col] = [1, get_random_flake()]
    else:
    print "\033[%s;%sH " % (snowflakes[col], col)
    print "\033[%s;%sH " % (snowflakes[col][0], col)

    snowflakes[col] += 1

    print "\033[%s;%sH*" % (snowflakes[col], 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
    snowflakes[col] = 1
    print "\033[%s;%sH*" % (snowflakes[col], col)
    flake = get_random_flake()
    snowflakes[col] = [1, flake]

    print "\033[%s;%sH%s" % (snowflakes[col][0], col,
    snowflakes[col][1])

    # keep any flakes on the screen moving
    # key any flakes on the screen moving
    for flake in snowflakes.keys():
    move_flake(flake)

  13. @sontek sontek revised this gist Dec 22, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion snowjob.py
    Original 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)

    # key any flakes on the screen moving
    # keep any flakes on the screen moving
    for flake in snowflakes.keys():
    move_flake(flake)

  14. @sontek sontek created this gist Dec 22, 2011.
    37 changes: 37 additions & 0 deletions snowjob.py
    Original 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)