Input Program

 

import ddf.minim.*;
import ddf.minim.analysis.*;

import gab.opencv.*;
import processing.video.*;
import java.awt.Rectangle;
Minim minim;
AudioPlayer song;
AudioPlayer song_1;
AudioPlayer song_2;
AudioPlayer song_3;
AudioPlayer song_4;
AudioPlayer song_5;
BeatDetect beat;

Capture video;
OpenCV opencv;
PImage HappyThoughts;
float eRadius;
float diam;
float x;
float y;
float r;
float g;
float b;
float a;
int counter;

PImage src;

int myPixel;

int maxColors = 4;
int[] hues;
int[] colors;
int rangeWidth = 200;

PImage[] outputs;

int colorToChange = -1;

void setup() {

size(600, 500, P3D);
video = new Capture(this, 640, 480);
opencv = new OpenCV(this, video.width, video.height);

colors = new int[maxColors];
hues = new int[maxColors];

outputs = new PImage[maxColors];

video.start();

minim = new Minim(this);
song = minim.loadFile (“happy thoughts.mp3”);
song_1 = minim.loadFile (“Fight The Feeling.mp3”);
song_2 = minim.loadFile (“Flume – Say It feat. Tove Lo.mp3”);
song_3 = minim.loadFile (“swell – im sorry (feat. shiloh).mp3”);
song_4 = minim.loadFile (“Sober.mp3”);
song_5 = minim.loadFile (“Ta-ku – Higher (Flume Remix).mp3”);
}

void draw() {

background(150);
counter ++;
r = random(255);
g = random(255);
b = random(255);
a = random(255);
x = random(width);
y = random(height);
diam = random(200);
if (video.available()) {
video.read();
}

opencv.loadImage(video);

opencv.useColor();
src = opencv.getSnapshot();
opencv.useColor(HSB);

detectColors();
image(src, 0, 0);
filter(POSTERIZE, 2.5);
filter(BLUR);
beat = new BeatDetect();
ellipseMode(RADIUS);
eRadius = 20;
eRadius *= .90;
if ( eRadius < 20 ) eRadius = 10;

{
for (int i = 0; i < song.bufferSize() – 1; i++)
{
if (i>10) {
noFill();
stroke(r, g, b, a);

line(x, 50 + song.left.get(i)*50, y, 50 + song.left.get(i+1)*50);
line(x, 400 + song.left.get(i)*50, y, 400 + song.left.get(i+1)*50);

line(x, 50 + song_1.left.get(i)*50, i+1, 50 + song_1.left.get(i+1)*50);
line(x, 400 + song_1.left.get(i)*50, i+1, 400 + song_1.left.get(i+1)*50);

line(x, 50 + song_3.left.get(i)*50, y, 50 + song_3.left.get(i+1)*50);
line(x, 400 + song_3.left.get(i)*50, y, 400 + song_3.left.get(i+1)*50);

line(x, 50 + song_2.left.get(i)*50, y, 50 + song_2.left.get(i+1)*50);
line(x, 400 + song_2.left.get(i)*50, y, 400 + song_2.left.get(i+1)*50);

line(x, 50 + song_4.left.get(i)*50, y, 50 + song_4.left.get(i+1)*50);
line(x, 400 + song_4.left.get(i)*50, y, 400 + song_4.left.get(i+1)*50);

line(x, 50 + song_5.left.get(i)*50, y, 50 + song_5.left.get(i+1)*50);
line(x, 400 + song_5.left.get(i)*50, y, 400 + song_5.left.get(i+1)*50);

line(x, y + song.left.get(i)*50, y, x + song.left.get(i+1)*50);
line(x, y + song.left.get(i)*50, y, x + song.left.get(i+1)*50);

line(x, y+ song_1.left.get(i)*50, i+1, x + song_1.left.get(i+1)*50);
line(x, y + song_1.left.get(i)*50, i+1, x + song_1.left.get(i+1)*50);

line(x, y + song_3.left.get(i)*50, y, x + song_3.left.get(i+1)*50);
line(x, y + song_3.left.get(i)*50, y, x + song_3.left.get(i+1)*50);

line(x, y + song_2.left.get(i)*50, y, x + song_2.left.get(i+1)*50);
line(x, y + song_2.left.get(i)*50, y, x + song_2.left.get(i+1)*50);

line(x, y + song_4.left.get(i)*50, y, x + song_4.left.get(i+1)*50);
line(x, y + song_4.left.get(i)*50, y, x + song_4.left.get(i+1)*50);

line(x, y + song_5.left.get(i)*50, y, x + song_5.left.get(i+1)*50);
line(x, y + song_5.left.get(i)*50, y, x + song_5.left.get(i+1)*50);
}

textSize(20);
stroke(255);
fill(255);

if (colorToChange > -1) {
text(“click to change color ” + colorToChange, 10, 25);
} else {
text(“press key [c] to select color”, 10, 25);
}
}
}
}

void detectColors() {

for (int i=0; i<hues.length; i++) {

if (hues[i] <= 0) continue;

opencv.loadImage(src);
opencv.useColor(HSB);
opencv.setGray(opencv.getH().clone());

int hueToDetect = hues[i];

opencv.inRange(hueToDetect-rangeWidth/2, hueToDetect+rangeWidth/2);
opencv.erode();

outputs[i] = opencv.getSnapshot();
}
if (outputs[0] != null) {

opencv.loadImage(outputs[0]);
;
}
}

void mousePressed() {

if (colorToChange > -1) {

color c = get(mouseX, mouseY);
println(“r: ” + red(c) + ” g: ” + green(c) + ” b: ” + blue(c));

if (red(c) >= 150) {
song.play();
song_1.pause();
song_2.pause();
song_3.pause();
song_4.pause();
song_5.pause();
}

if (red(c) >= 130) {
song_3.play();
song.pause();
song_1.pause();
song_2.pause();
song_4.pause();
song_5.pause();
}
if (blue(c) >= 150) {
song_1.play();
song.pause();
song_2.pause();
song_3.pause();
song_4.pause();
song_5.pause();
}
if (blue(c) >= 130) {
song_4.play();
song.pause();
song_1.pause();
song_2.pause();
song_3.pause();
song_5.pause();
}

if (green(c) >= 150) {
song_2.play();
song.pause();
song_1.pause();
song_3.pause();
song_4.pause();
song_5.pause();
}
if (green(c) >= 130) {
song_5.play();
song.pause();
song_1.pause();
song_2.pause();
song_3.pause();
song_4.pause();
}

int hue = int(map(hue(c), 0, 255, 255, 255));

colors[colorToChange-1] = -1;
hues[colorToChange-1] = hue;

println(“color index ” + (colorToChange-1) + “, value: ” + hue);
}
}
void keyPressed() {

if (key == ‘c’) {
colorToChange = 1;
}
if (key ==’2′) {
song.pause();
song_1.pause();
song_2.pause();
song_3.pause();
song_4.pause();
song_5.pause();
}
}

void keyReleased() {
colorToChange = -1;
}

This entry was posted in Time Based and tagged , , , , . Bookmark the permalink.

Leave a comment