Skip to content

Instantly share code, notes, and snippets.

@mitchellvitez
Last active February 9, 2022 23:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mitchellvitez/488a1ce90d9e4a897a5d0cefbd5e1b89 to your computer and use it in GitHub Desktop.
Save mitchellvitez/488a1ce90d9e4a897a5d0cefbd5e1b89 to your computer and use it in GitHub Desktop.
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