-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrain.py
44 lines (36 loc) · 887 Bytes
/
rain.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
38
39
40
41
42
43
from time import sleep
from random import randint
import fcntl, termios, struct
def render():
print('\033[2J')
for r in data:
for c in r:
v = states[c] if c < len(states) else states[-1]
print(v,end='')
print('')
def update():
for ir in range(len(data)-1,-1,-1):
for ic, c in enumerate(data[ir]):
if randint(1,1000) > 999:
data[ir][ic] += randint(1,3)
if c > 2:
data[ir][ic] -= c
if ir < len(data) -1:
data[ir+1][ic] += c
def terminal_size():
th, tw, hp, wp = struct.unpack('HHHH',
fcntl.ioctl(0, termios.TIOCGWINSZ,
struct.pack('HHHH', 0, 0, 0, 0)))
return tw, th
width,height = terminal_size()
data = []
states = list(' .,:;|oO')
for _ in range(height):
row = []
for __ in range(width):
row.append(0)
data.append(row)
while True:
render()
update()
sleep(0.075)