- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfalling_code.py
More file actions
Latest commit
68 lines (56 loc) · 2.06 KB
/
Copy pathfalling_code.py
File metadata and controls
68 lines (56 loc) · 2.06 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
importos
importsys
fromsysimportstdout
importrandom
fromtimeimportsleep
fromstringimportascii_letters, digits, punctuation
importargparse
parser=argparse.ArgumentParser()
parser.add_argument('-he', '--height', type=int, default=18, help='height of falling string')
parser.add_argument('-s', '--speed', type=float, default=.035, help='time between lines in seconds')
args=parser.parse_args()
# Does not work for linux
#os.system('cls')
STRING=ascii_letters+digits+punctuation
classAnsi:
green='32'
reset='0'
bright='1'
dim='2'
normal='22'
lightgreen='92'
def__init__(self):
fornameindir(self):
ifnotname.startswith('_'):
setattr(self, name, f'\033[{getattr(self, name)}m')
deffalling_code(length=20, speed=.045):
style=Ansi()
cols=os.get_terminal_size().columns
line= [0forxinrange(cols)]
whileTrue:
cols=os.get_terminal_size().columns
iflen(line) !=cols:
os.system('cls')
line= [0for_inrange(cols)]
new=random.choice([xforxinrange(len(line)) ifline[x] ==0])
line[new] +=1
foriinline:
stdout.write(style.green)
ifi==length:
stdout.write(style.reset+random.choice(STRING))
elifi==0:
stdout.write(' ')
elif1<=i<=length//4:
stdout.write(style.dim+random.choice(STRING))
eliflength//4<i<=round((length/4)*2):
stdout.write(style.normal+random.choice(STRING))
elifround((length/4)*2) <i<round((length/4)*3):
stdout.write(style.bright+random.choice(STRING))
else:
stdout.write(style.reset+style.lightgreen+style.bright+random.choice(STRING))
stdout.write(style.reset)
line= [x+1ifx<lengthandx!=0else0forxinline]
sys.stdout.flush()
sleep(speed)
if__name__=='__main__':
falling_code(length=args.height, speed=args.speed)