This is all code for three projects I’ve done for DMS8013:
Webcam Synthesizer
//some functions are learned from Minim library
import processing.video.*;
import processing.sound.*;
import ddf.minim.*;
import ddf.minim.ugens.*;Minim minim;
AudioOutput out;
MoogFilter moog;
Capture cam;
Oscil wave;int scanX = 0, scanY = 250;
void setup() {
cam = new Capture(this, 1280, 720);
cam.start();
size(1280, 500);minim = new Minim(this);
out = minim.getLineOut();
moog = new MoogFilter( 1200, 0.5 );
out = minim.getLineOut(Minim.STEREO);
wave = new Oscil( 440, 0.5f, Waves.SINE );
wave.patch(out);
Noise noize = new Noise( 0.5f );
noize.patch(moog).patch(out);
}void draw() {
if (scanX >= cam.width || scanX >= width) {
scanX = 0;
scanY++;
if (scanY >= cam.height || scanX >= height)
scanY = 0;
}if (cam.available()) {
cam.read();
}image(cam, 0, 0);
int scanCol = get(scanX, scanY);
float scanHue = hue(scanCol);
int highlight = color(255, 255, 255, scanHue);
fill(highlight);
noStroke();
ellipse(scanX-5, scanY-5, 10, 10);float freq = map(scanHue, 0, 255, 900, 250);
wave.setFrequency(freq);float rez = map(scanX, 0, width, 0, 7);
moog.resonance.setLastValue(rez);}
Slit-scan Box
//The slit-scanning technique (code) below was learned from Daniel Shiffman’s Slit-scan video tutorial on YouTube https://www.youtube.com/watch?v=WCJM9WIoudI
import processing.video.*;
Capture cam;
int videoSliceX;
int drawPositionX;void setup() {
size(1200, 480);cam = new Capture(this,1200, 480);
cam.start();
videoSliceX = cam.width / 2;
drawPositionX = width – 1;
background(0);
}
void keyPressed () {if(keyCode == LEFT) {
videoSliceX = cam.width / 3;
}
if(keyCode == RIGHT){
videoSliceX = cam.width / 2;
}
if(keyCode == DOWN){
drawPositionX = width – 1;
}
if(keyCode == UP){
videoSliceX = cam.height / 2;
}}
void draw() {
if (cam.available()) {
cam.read();
cam.loadPixels();loadPixels();
for (int y = 0; y < cam.height; y++){
int setPixelIndex = y*width + drawPositionX;
int getPixelIndex = y*cam.width + videoSliceX;
pixels[setPixelIndex] = cam.pixels[getPixelIndex];
}
updatePixels();drawPositionX–;
if (drawPositionX < 0) {
drawPositionX = width – 1;
}}
}
Particle Modulation
//The Particle class code below was learned from Daniel Shiffman’s tutorial https://www.youtube.com/watch?v=WH31daSj4nc and Tom Schofield’s lecture back in October 2015
import processing.video.*;
import ddf.minim.*;
import ddf.minim.ugens.*;
Minim minim;
AudioOutput out;
Particle[] particles;
Oscil fm;int scanX = 320, scanY =180;
Capture cam;
void setup() {
size(640, 360);cam = new Capture(this, width, height);
cam.start();
particles = new Particle [300];
for (int i = 0; i < particles.length; i++) {
particles[i] = new Particle();
}
background(0);minim = new Minim( this );
out = minim.getLineOut();
Oscil wave = new Oscil( 200, 0.8, Waves.TRIANGLE );
fm = new Oscil( 10, 2, Waves.SINE );
fm.offset.setLastValue( 200 );
fm.patch( wave.frequency );
wave.patch( out );
}void captureEvent(Capture video) {
video.read();
}void draw() {
for (int i = 0; i < particles.length; i++) {
particles[i].display();
particles[i].move();
}int scanCol = cam.get(scanY, scanX);
float scanHue = hue(scanCol);int scanCol2 = cam.get(scanX, scanY);
float scanBright = brightness(scanCol2);{
float modulateAmount = map(scanBright, 0, height, 220, 1);
float modulateFrequency = map(scanHue, 0, width, 0.1, 100);fm.setFrequency(modulateFrequency);
fm.setAmplitude(modulateAmount);
}
}