Skip to content

Instantly share code, notes, and snippets.

@hecanjog
Created October 4, 2012 19:33
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 hecanjog/3835872 to your computer and use it in GitHub Desktop.
Save hecanjog/3835872 to your computer and use it in GitHub Desktop.
### erik@hecanjog.com # October 4 2012 # Milwaukee ###
from PIL import Image
import dsp
import subprocess
img = Image.open('blue.jpg')
original = img.copy()
img = img.crop((0, 0, 640, 480))
out = ''
type = 'jump'
frame_count = 0
def tone(type='jump', partials=1):
""" TODO: add more sound generators, explore frame groupings and masks """
if type == 'jump':
frames = 1470 / partials
wform = dsp.wavetable('random', frames)
out = dsp.fill(''.join([ dsp.pack(c) * 2 for c in wform ]), 1470)
elif type == 'sit':
out = dsp.mix([ dsp.fill(''.join([ dsp.pack(c) * 2 for c in dsp.wavetable('sine2pi', 1470 / (i +1)) ]), 1470) for i in range(partials) ])
out = dsp.pan(out, dsp.rand())
return out
for s in range(120):
curve = dsp.breakpoint([dsp.rand() for c in range(10)], 30)
for i in range(30):
frame_count += 1
partials = dsp.randint(1, 10)
uptrig = dsp.randint(0, 30)
downtrig = dsp.randint(0, 30)
if s % 5 == 1 and (i == uptrig or i == downtrig):
type = dsp.randchoose(['jump', 'sit'])
out += tone(type, partials)
q = int(50 * curve[i] + 40)
up = dsp.randint(0, dsp.randint(30, 300)) if s % 5 == 1 and i == uptrig else 0
down = dsp.randint(0, dsp.randint(30, 300)) if s % 5 == 1 and i == downtrig else 0
img = img.offset(up, down)
img.save('video/blue-' + str(frame_count) + '.jpg', 'JPEG', quality=q)
img = Image.open('video/blue-' + str(frame_count) + '.jpg')
if s % 5 == 0:
img = original
a, b = dsp.randint(0, 1000), dsp.randint(0, 1000)
c, d = a + 640, b + 480
img = img.crop((a, b, c, d))
dsp.write(out, 'blue', False)
subprocess.call('ffmpeg -framerate 30 -i video/blue-%d.jpg -i renders/blue.wav -shortest -sameq blue.avi', shell=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment