Skip to content

Commit 8b5165a

Browse files
authored
Added 1.2 version support for main.py
Added multiple threads which cuts the load time in half! Also uses better ASCII encoding
1 parent 338b2ff commit 8b5165a

File tree

1 file changed

+161
-18
lines changed

1 file changed

+161
-18
lines changed

main.py

Lines changed: 161 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,167 @@
11
from PIL import Image
2+
from time import sleep
23
from os import system
34
from silver import Silver
5+
from threading import Thread
46

5-
text = []
6-
for i in range(1, 3286): # There are 1095 frames
7-
filename = f"new{i}.png"
8-
with Image.open(filename) as image:
9-
frame = ''.join('#' if pix > 50 else '.' for pix in image.getdata(0))
10-
text.append(frame)
11-
if i % 10 == 0:
12-
print(f"{i}/3285")
13-
print("Ready to play!")
14-
from time import sleep
15-
sleep(1)
16-
system("clear")
17-
for i in range(80):
18-
print("e", end="")
7+
frames = []
8+
9+
w1 = []
10+
w2 = []
11+
w3 = []
12+
w4 = []
13+
def wk1():
14+
for i in range(1,1000):
15+
filename = f"new{i}.png"
16+
with Image.open(filename) as image:
17+
# 255 = @
18+
# 200 = &
19+
# 150 = #
20+
# 100 = $
21+
# 50 = +
22+
# 30 = -
23+
# 20 = .
24+
# <20 = " "
25+
frame = ""
26+
for pix in image.getdata(0):
27+
if pix == 255:
28+
frame += "@"
29+
elif pix >= 200:
30+
frame += "&"
31+
elif pix >= 150:
32+
frame += "#"
33+
elif pix >= 100:
34+
frame += "$"
35+
elif pix >= 50:
36+
frame += "+"
37+
elif pix >= 30:
38+
frame += "-"
39+
elif pix >= 20:
40+
frame += "."
41+
else:
42+
frame += " "
43+
w1.append(frame)
44+
def wk2():
45+
for i in range(1000,2000):
46+
filename = f"new{i}.png"
47+
with Image.open(filename) as image:
48+
# 255 = @
49+
# 200 = &
50+
# 150 = #
51+
# 100 = $
52+
# 50 = +
53+
# 30 = -
54+
# 20 = .
55+
# <20 = " "
56+
frame = ""
57+
for pix in image.getdata(0):
58+
if pix == 255:
59+
frame += "@"
60+
elif pix >= 200:
61+
frame += "&"
62+
elif pix >= 150:
63+
frame += "#"
64+
elif pix >= 100:
65+
frame += "$"
66+
elif pix >= 50:
67+
frame += "+"
68+
elif pix >= 30:
69+
frame += "-"
70+
elif pix >= 20:
71+
frame += "."
72+
else:
73+
frame += " "
74+
w2.append(frame)
75+
def wk3():
76+
for i in range(2000,3000):
77+
filename = f"new{i}.png"
78+
with Image.open(filename) as image:
79+
# 255 = @
80+
# 200 = &
81+
# 150 = #
82+
# 100 = $
83+
# 50 = +
84+
# 30 = -
85+
# 20 = .
86+
# <20 = " "
87+
frame = ""
88+
for pix in image.getdata(0):
89+
if pix == 255:
90+
frame += "@"
91+
elif pix >= 200:
92+
frame += "&"
93+
elif pix >= 150:
94+
frame += "#"
95+
elif pix >= 100:
96+
frame += "$"
97+
elif pix >= 50:
98+
frame += "+"
99+
elif pix >= 30:
100+
frame += "-"
101+
elif pix >= 20:
102+
frame += "."
103+
else:
104+
frame += " "
105+
w3.append(frame)
106+
def wk4():
107+
for i in range(3000,3286):
108+
filename = f"new{i}.png"
109+
with Image.open(filename) as image:
110+
# 255 = @
111+
# 200 = &
112+
# 150 = #
113+
# 100 = $
114+
# 50 = +
115+
# 30 = -
116+
# 20 = .
117+
# <20 = " "
118+
frame = ""
119+
for pix in image.getdata(0):
120+
if pix == 255:
121+
frame += "@"
122+
elif pix >= 200:
123+
frame += "&"
124+
elif pix >= 150:
125+
frame += "#"
126+
elif pix >= 100:
127+
frame += "$"
128+
elif pix >= 50:
129+
frame += "+"
130+
elif pix >= 30:
131+
frame += "-"
132+
elif pix >= 20:
133+
frame += "."
134+
else:
135+
frame += " "
136+
w4.append(frame)
137+
138+
# Run our workers
139+
f = Thread(target=wk1)
140+
u = Thread(target=wk2)
141+
c = Thread(target=wk3)
142+
k = Thread(target=wk4)
143+
144+
f.start()
145+
u.start()
146+
c.start()
147+
k.start()
148+
149+
# We need to wait til out workers are finished since they are non-blocking
150+
while len(w1) < 997 or len(w2) < 997 or len(w3) < 997 or len(w4) < 283:
151+
print(len(w2))
152+
sleep(2)
153+
# ITS MORPHIN TIME
154+
for frame in w1:
155+
frames.append(frame)
156+
for frame in w2:
157+
frames.append(frame)
158+
for frame in w3:
159+
frames.append(frame)
160+
for frame in w4:
161+
frames.append(frame)
162+
print("playing")
19163
Silver.play("badapple.mp3")
20-
for frame in text:
21-
print(frame, end="")
22-
sleep(0.063)
164+
for frame in frames:
23165
system("clear")
24-
Silver.stop()
166+
print(frame)
167+
sleep(0.062)

0 commit comments

Comments
 (0)