Algorithmic Media

From Media Design: Networked & Lens-Based wiki
Revision as of 13:24, 11 September 2009 by Michael Murtaugh (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search


Sound

#!/usr/bin/python

import os

pat1 = "ooo.oo.o.oo."
pat2 = pat1

def do (cmd):
	os.system(cmd)

do("rm tmp.raw")

for i in range(13):
	print pat1
	print pat2
	print "----"

	for i in range(4):
		for (a, b) in zip(pat1, pat2):
			if a=="o" and b=="o":
				do("cat tones/sample.raw >> tmp.raw")
			elif a=="o" or b=="o":
				do("cat tones/lo.raw >> tmp.raw")
			else:
				do("cat tones/silence.raw >> tmp.raw")

	pat2 = pat2[1:]+pat2[0]

do("cat tmp.raw | sox -t raw -r 44100 -sw -c 2 - -t .wav pat.wav")
do("rm tmp.raw")

Image Generation

import os, struct
import math

f = open("test.rgba", "wb")

def do (cmd):
	os.system(cmd)

(red, green, blue) = (255, 0, 0)

for x in range(480):
	for y in range(480):
		# alpha = int(255 * (y / 480.0))
		dx = (240 - x)
		dy = (240 - y)
		d = math.sqrt(dy**2 + dx**2)

		alpha = min(255, max(0 , int(255 * (d / 240.0)) ))
		data = struct.pack("<BBBB", red, green, blue, alpha)
		f.write(data)

f.close()

do("convert -size 480x480 -depth 8 rgba:test.rgba test.png")
import os, struct

i = open("papert.raw", "rb")

f = open("test.rgb", "wb")

for y in range(480):
	for x in range(480):
		
		pixel = i.read(3)
		(r, g, b) = struct.unpack("<BBB", pixel)


		if y % 2 == 0:
			red = x % 255
			green = y % 255
			blue = 0
			data = struct.pack("<BBB", red, green, blue)
		else:
			data = struct.pack("<BBB", r, g, b)

		f.write(data)

Movie

Media:Genmov.zip