This repository has been archived by the owner on Nov 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
fuse.py
executable file
·134 lines (104 loc) · 3.42 KB
/
fuse.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/env python
import os, sys, random, time, signal, math
def exit(sig, frame):
print("\033[?25h")
os.system("clear")
sys.exit(0)
signal.signal(signal.SIGINT, exit)
def get_scr_size():
return [int(x) for x in os.popen("stty size", "r").read().split()]
def init():
global scr, img
os.system("clear")
scr = get_scr_size()
chars = [
[""],
[".", "'"],
[":", ";"],
["*", "#"],
["$", "&"],
["#"]
]
def char(p):
for i in range(len(chars)):
if i +1 >= (1 -p) *len(chars):
return chars[i][random.randint(0, len(chars[i]) -1)]
return ""
def ang2vec(a, r): return [int(math.cos(a) *r), int(math.sin(a) *r *1.5)] #y, x
def vec2ang(v): return math.atan(v[1] /v[0]) +(v[0] < 0 and 180 or 0)
def dis(p0, p1): return ((abs(p0[0] -p1[0]) *2) **2 +abs(p0[1] -p1[1]) **2) **.5
def tile2win(p): return [p[0] %(scr[0] -1) +1, p[1] %scr[1] +1]
trail = []
colors = [1, 5, 4, 6, 2, 3]
count = 1
erase = 1
tailsize = 1000
for i in sys.argv[1:]:
if i[:3] == "-c=":
try: count = int(i[3:])
except: pass
elif i[:8] == "--count=":
try: count = int(i[8:])
except: pass
elif i[:3] == "-e=":
try: erase = int(i[3:])
except: pass
elif i[:8] == "--erase=":
try: erase = int(i[8:])
except: pass
elif i[:3] == "-t=":
try: tailsize = int(i[3:])
except: pass
elif i[:8] == "--tailsize=":
try: tailsize = int(i[11:])
except: pass
elif i == "-h" or i == "--help" or i == "--usage":
print("fuse.py [OPTIONS]")
print("\n".join([
"-c=<count> default: " +str(count),
"-e=<erase (0/1)> default: " +str(erase),
"-t=<tailsize> default: " +str(tailsize)
]))
sys.exit(0)
print("\033[?25l")
def dot(y, x, r, c=37):
global erase, trail
for m in range(r *2 +1):
for n in range(r *4 +1):
p = tile2win([y -r +m, x -r *2 +n])
ch = char(dis([y, x], p) /r)
ch = ch == "#" and chr(random.randint(33, 126)) or ch
if ch:
print("\033[" +str(30 +colors[c]) +"m\033[" +str(p[0]) +";" +str(p[1]) +"H" +ch +"\033[0m")
if erase: trail.insert(0, p)
def cleanup():
global tailsize, trail
spark = "%%%/!.^'"
for i in range(len(trail) -1, tailsize, -1):
if i > tailsize +100:
if random.randint(0, 1) == 0:
if trail[:tailsize].count(trail[i]) == 0:
print("\033[" +str(trail[i][0]) +";" +str(trail[i][1]) +"H ")
trail.pop(i)
else:
if random.randint(0, 10) == 0:
if trail[:tailsize].count(trail[i]) == 0:
print("\033[" +str(trail[i][0]) +";" +str(trail[i][1]) +"H" +spark[random.randint(0, len(spark) -1)])
init()
pos = [[int(scr[0] /2), int(scr[1] /2)]] *count
ang = [0] *count
c = []
for _ in range(count): c += [random.randint(0, 5)]
while 1:
for i in c: i = (i +1) %6
for _ in range(4):
d = []
for i in range(count): d += [random.randint(-60, 60) *math.pi /360]
for _ in range(8):
for i in range(count):
ang[i] += d[i]
vec = ang2vec(ang[i], 3)
pos[i] = tile2win([pos[i][0] +vec[0], pos[i][1] +vec[1]])
time.sleep(.02)
dot(pos[i][0], pos[i][1], 5, c[i])
if erase: cleanup()