Skip to content

Instantly share code, notes, and snippets.

@mitchellvitez
Last active February 9, 2022 23:16
Embed
What would you like to do?
Violin animation made out of many tiny notes. Frames rendered in parallel.
from PIL import Image
import random
import multiprocessing
background = Image.new('RGBA', (2048, 2048), (255, 255, 255, 255))
image = Image.open(r"violin.jpg").convert('RGBA').load()
note = Image.open(r"note.png").convert('RGBA')
def gen_frame(frame):
for x in range(2048):
for y in range(2048):
if random.random() < 0.04 and image[x, y][0] / 255. < random.random():
background.alpha_composite(note, (x, y))
background.save(f'out/{frame}.png')
if __name__ == '__main__':
pool = multiprocessing.Pool()
pool.map(gen_frame, range(60))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment