Advertisement
Marrin

Snowflakes 1

Jan 23rd, 2014
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.07 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import sys
  3. from functools import partial
  4. from itertools import chain
  5. from random import randrange
  6. from subprocess import check_output
  7. from time import sleep
  8.  
  9.  
  10. clear_screen = partial(sys.stdout.write, '\033[2J')
  11.  
  12.  
  13. def cursor_at(row, column):
  14.     sys.stdout.write('\033[{0};{1}H'.format(row, column))
  15.  
  16.  
  17. cursor_home = partial(cursor_at, 0, 0)
  18.  
  19.  
  20. def write_at(row, column, text):
  21.     cursor_at(row, column)
  22.     sys.stdout.write(text)
  23.  
  24.  
  25. def main():
  26.     row_count, column_count = map(int, check_output(['stty', 'size']).split())
  27.     flakes = list()
  28.     clear_screen()
  29.     while True:
  30.         next_flakes = list()
  31.         for row, column in chain(flakes, [(0, randrange(column_count))]):
  32.             if row <= row_count:
  33.                 write_at(row, column, ' ')
  34.                 row += 1
  35.                 next_flakes.append((row, column))
  36.                 write_at(row, column, u'\u2743 ')
  37.                 cursor_home()
  38.         flakes = next_flakes
  39.         sys.stdout.flush()
  40.         sleep(0.1)
  41.  
  42.  
  43. if __name__ == '__main__':
  44.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement