calvinloke / bad-apple Goto Github PK
View Code? Open in Web Editor NEWBad Apple printed out on the console with Python!
Bad Apple printed out on the console with Python!
Forked your repo, and had a look, also had a look about the suggestions made by the other user, but honestly, cv2 and the way you're currently doing the ascii conversion, is over my head slightly. If I properly sat down and read it, I might get somewhere, but anyways.
I've tweaked your script to also use threading on the frames, so it should be faster. Also, completely removed the need to save to a file, twice, by just directly passing the cv2 result to PIL, and then outputting the frames, though I do like the idea for keeping the frames, which is why I'm also looking into perhaps RLE compressing the frames into a single file, instead of having a whole folder of 7kb ASCIIs.
I'm not really sure if you wanted the tweaks I made in your version, so I made it as a separate file on my repo and put this as a issue, instead of a PR (though if comments were a thing, I'd put it there), if you just want to take a look. Just as someone who vaguely knows Python, this was a nice project to at least be able to work on.
Oh, and progress bar still works!
block=False is not supported in Linux, you may need to add an thread to execute playsound():
import threading
...
threading.Thread(target=playsound, args=("tng_bad-apple.mp3",)).start()
Traceback (most recent call last):
File "touhou_bad_apple_v4.0.py", line 1, in
import cv2
ImportError: No module named cv2
At the end, theres that. :I
it works perfectly until it reaches the end
Python 3.9 has been used.
Afaik Python 3.10 has some issues cause this hasn't been optimized for Python 3.10 or newer.
Traceback (most recent call last):
File "/home/hax/GitHub/bad-apple/touhou_bad_apple_v4.5.py", line 181, in <module>
main()
File "/home/hax/GitHub/bad-apple/touhou_bad_apple_v4.5.py", line 171, in main
play_video(total_frames=total_frames)
File "/home/hax/GitHub/bad-apple/touhou_bad_apple_v4.5.py", line 37, in play_video
sys.stdout.write("\r" + ASCII_LIST[frame_number])
IndexError: list index out of range
Hi, I saw the code on touhou_bad_apple_v2.py
and I though of some possible speed improvements right off the bat.
First is ASCII generation. As you're doing right now, the best way to improve processing speed is by creating a Pool and allocating each frame to a worker until the frame extraction is over. The disadvantage is that you lose the current progress bar you have implemented, and instead will need something more complex like an N lines progress bar, one for each worker in the pool, or a signaling method between threads, like a semaphore, and is just too much work for what the current project is aiming for. You can also improve the video quality by adding more characters to the list, more specifically a space(all black) " "
and a block character(all white) "\u2588"
, and adapting the padding calculation on line 86 to include the new characters.
Another improvement, and probably the most important one, is saving the ASCII frames to a single file containing all frames, instead of multiple files. The reasoning is that opening and closing files takes time, which would be better spent synchronizing the frames in the terminal.
Checking files also takes time. As of right now, you are manually checking every single .txt
file for all the frames and checking if they exist. This can be done much faster if you use instead os.listdir()
and filter the results containing the string .txt
, then count the results(or a single file if you use the approach above). Also, please always use os.path.join()
instead of manually using /
. Reasoning is that the os.path
library provides cross-platform separators and better handling of absolute paths, which is much less error prone.
I could make a fork and do those changes, but I think it would be very useful if you did them yourself, since you can learn new skills and functions with them. Tell me what you think about my suggestions, then close this issue later.
Edit: my mistake, I just noticed you changed to a white background in the video. Correct characters are a space(all white) " "
and a block character(all black) "\u2588"
Hey :) Its been a while since my last ticket :)
I have a new one for yaa. Even when this project was a weekend project. im still amazed about your progress..
It seems to be that there is something wrong with the audio format...
see log:
Select option:
Amazing job! I have some ideas for things I'd like to make by adapting your code, but I can't with no copyright info attached to the code. I would suggest the timeless GNU Public License: https://www.gnu.org/licenses/gpl-3.0.en.html
I never used Python but I really wanted to try this. I followed all the steps.
\Desktop\bad-apple-master\touhou_bad_apple_v3.py", line 7, in
from PIL import Image
ModuleNotFoundError: No module named 'PIL'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.