Skip to content

Instantly share code, notes, and snippets.

@perky
Created July 19, 2013 19:40
Show Gist options
  • Save perky/6041837 to your computer and use it in GitHub Desktop.
Save perky/6041837 to your computer and use it in GitHub Desktop.
import processing.video.*;
import oscP5.*;
class Preset
{
public void activate(PImage src, PImage dst) {}
}
Capture video;
//Movie video;
PImage output;
Preset a, b, c;
Preset currentPreset;
OscP5 oscP5;
void setup() {
size(1280, 720);
// Print out a list of available video sources.
String[] cameras = Capture.list();
for (int i = 0; i < cameras.length; i++) {
println(cameras[i]);
}
// Uses the default video input, see the reference if this causes an error
video = new Capture(this, width, height, "Built-in iSight", 30);
video.start();
//video = new Movie(this, "/Volumes/Cheetah/Projects/Locofilm Showreel/Renders/JAMESLAID.mp4");
//video.loop();
output = createImage(width, height, RGB);
noStroke();
smooth();
oscP5 = new OscP5(this,9999);
a = new Preset() {
public void activate(PImage src, PImage dst) {
dst.copy(src, 0, 0, src.width, src.height, 0, 0, width / 2, height / 2);
dst.copy(src, 0, 0, src.width, src.height, width / 2, 0, width / 2, height / 2);
dst.copy(src, 0, 0, src.width, src.height, 0, height / 2, width / 2, height / 2);
dst.copy(src, 0, 0, src.width, src.height, width / 2, height / 2, width / 2, height / 2);
}
};
b = new Preset() {
public void activate(PImage src, PImage dst) {
dst.copy(src, 0, 0, src.width/2, src.height/2, 0, 0, width, height);
}
};
c = new Preset() {
public void activate(PImage src, PImage dst) {
dst.copy(src, 0, 0, src.width, src.height, 0, 0, width, height);
}
};
currentPreset = a;
}
void draw() {
if (video.available()) {
video.read();
video.loadPixels();
currentPreset.activate(video, output);
}
image(output, 0, 0, width, height);
}
void keyPressed()
{
if (key == '1') {
currentPreset = a;
} else if (key == '2') {
currentPreset = b;
} else if (key == '3') {
currentPreset = c;
}
}
/* incoming osc message are forwarded to the oscEvent method. */
void oscEvent(OscMessage oscMsg) {
int buttonDown = oscMsg.get(1).intValue();
if (oscMsg.addrPattern().equals("/gyrosc/button") && buttonDown == 1) {
int buttonNum = oscMsg.get(0).intValue();
if (buttonNum == 1) {
currentPreset = a;
} else if (buttonNum == 2) {
currentPreset = b;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment