├── README.md ├── bad_apple.mp3 ├── bad_apple.mp4 ├── console-writer.py ├── custom_ascii_converter.py └── video-to-frames.py /README.md: -------------------------------------------------------------------------------- 1 | # Bad Apple! in Python Console 2 | 3 | Over the past few years, the meme of playing Bad Apple!! on a variety of odd things has become more and more popular, so I decided to add to it. This was developed over the course of a single weeked in November of 2022. 4 | 5 | Below is a portion of the demo: 6 | 7 | https://github.com/SetuMar/bad-apple/assets/82828034/06f189fa-9b5f-4407-acf8-f5da9e90ed59 8 | 9 | *The full video can be found here: https://www.youtube.com/watch?v=tjSRx2eydwk* 10 | 11 | NOTE: run the file `video-to-frames.py` script **before** running the `console-writer.py` script. 12 | 13 | # Needed Libraries 14 | - OpenCV (splitting video into image frames) 15 | - Pygame (playing audio - I couldn't get anything else to work the way I wanted!) 16 | - PIL (used for displaying images) 17 | - Copy (used to create a copy in the code) 18 | - OS (used to make folders and store frames) 19 | - Time (used to wait for a bit) 20 | -------------------------------------------------------------------------------- /bad_apple.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SetuMar/Bad-Apple/dd868a6fe06d948df4b4648a15ce4e9065bbd559/bad_apple.mp3 -------------------------------------------------------------------------------- /bad_apple.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SetuMar/Bad-Apple/dd868a6fe06d948df4b4648a15ce4e9065bbd559/bad_apple.mp4 -------------------------------------------------------------------------------- /console-writer.py: -------------------------------------------------------------------------------- 1 | import os 2 | import time 3 | import custom_ascii_converter 4 | import pygame 5 | 6 | pygame.init() 7 | 8 | pygame.mixer.music.load('bad_apple.mp3') 9 | 10 | image_locations = None 11 | 12 | for a, b, path in os.walk('video-frames'): 13 | image_locations = path 14 | 15 | index_image = {} 16 | 17 | for loc in image_locations: 18 | index_image.update({int(loc.split('e')[1].split('.')[0]):loc}) 19 | 20 | index_image = dict(sorted(index_image.items())) 21 | sorted_image_location = index_image.values() 22 | 23 | print("loading...") 24 | 25 | time.sleep(3) 26 | pygame.mixer.music.play() 27 | 28 | for image_loc in sorted_image_location: 29 | full_path = 'video-frames/' + image_loc 30 | 31 | custom_ascii_converter.generate_ascii_image(full_path, 15) 32 | 33 | time.sleep(0.024) 34 | 35 | print("VIDEO OVER. CLOSE THE CONSOLE, WEABOO") -------------------------------------------------------------------------------- /custom_ascii_converter.py: -------------------------------------------------------------------------------- 1 | import PIL.Image as pillow 2 | import copy 3 | 4 | def generate_ascii_image(path, height_division_amt): 5 | image = pillow.open(path) 6 | 7 | height_division_amt = height_division_amt 8 | width_division_amt = height_division_amt/2 9 | 10 | sized_image = image.resize((int(image.width/width_division_amt), int(image.height/height_division_amt))) 11 | 12 | img_data = sized_image.getdata() 13 | 14 | character = ['@', '#', 'S', '%', '?', '*', '+', ';', ':', ',', '.'] 15 | 16 | output = "" 17 | 18 | for p in img_data: 19 | output += character[p[0]//25] 20 | 21 | image_width = sized_image.width 22 | 23 | last = 0 24 | 25 | for index, char in enumerate(copy.copy(output)): 26 | if index % image_width == 0: 27 | print(output[last:index]) 28 | last = index 29 | -------------------------------------------------------------------------------- /video-to-frames.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import os 3 | 4 | video = cv2.VideoCapture('bad_apple.mp4') 5 | current_frame = 0 6 | 7 | if not os.path.exists('video-frames'): 8 | os.makedirs('video-frames') 9 | 10 | while True: 11 | try: 12 | success, frame = video.read() 13 | cv2.imshow("Output", frame) 14 | cv2.imwrite('video-frames/frame' + str(current_frame) + '.jpg', frame) 15 | current_frame += 1 16 | except: 17 | break --------------------------------------------------------------------------------