-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnow.py
37 lines (31 loc) · 877 Bytes
/
snow.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# Jacobus Burger (2023)
# Just for fun, based on a video from Engineer Man
import os
import random
from time import sleep
DENSITY = 5
DELAY = 0.3
flakes = ['λ', '•', '.', '❆', '❅', '❄', '*']
width, height = os.get_terminal_size()
# initialize display to all empty characters
grid = [[' '] * width for _ in range(height)]
while True:
# draw grid
os.system('cls' if os.name == 'nt' else 'clear')
print('\033[?25l') # ANSI clear cursor code
display = ''
for row in grid:
display += ''.join(row) + '\n'
display = display.strip('\n')
print(display, end='')
# scroll everything down once
row = []
for _ in range(width):
if random.random() < DENSITY / 100:
row.append(random.choice(flakes))
else:
row.append(' ')
grid.insert(0, row)
grid.pop()
# wait
sleep(DELAY)