-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path20_digital_stream.py
More file actions
43 lines (37 loc) · 1.17 KB
/
20_digital_stream.py
File metadata and controls
43 lines (37 loc) · 1.17 KB
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
import random, sys, time, shutil
WIDTH,_=shutil.get_terminal_size((20,80)) # (20,80) are fallback values
# We can't print to the last column on Windows without it adding a
# newline automatically, so reduce the width by one:
WIDTH-=1
MATRIX_STR=('0','1','#','@','!','$',chr(1000))
COL_DENSITY=0.03
MIN_LEN=7
MAX_LEN=14
PAUSE=0.1
def main():
print('press ctrl-c to stop\n\n')
time.sleep(2)
columns=[0]*WIDTH
while True:
# set counter for each col
# this basically checks wether to start string
# or not on a particular col in each run
for i in range(WIDTH):
if columns[i] == 0:
if random.random() < COL_DENSITY:
columns[i]=random.randint(MIN_LEN,MAX_LEN)
# Display an empty space or a 1/0 character.
if columns[i] > 0:
print(random.choice(MATRIX_STR),end='',flush=True)
# imp step
columns[i]-=1
else:
print(' ',end='',flush=True)
print()
# sys.stdout.flush()
time.sleep(PAUSE)
if __name__=='__main__':
try:
main()
except KeyboardInterrupt:
sys.exit()