lunes, 26 de mayo de 2014
lunes, 19 de mayo de 2014
Algoritmo
import ddf.minim.*;
import processing.video.*;
Capture video;
Minim minim;
Minim minimA;
Minim minimV;
Minim minimR;
AudioPlayer effect;
AudioPlayer soundA;
AudioPlayer soundV;
AudioPlayer soundR;
boolean sound;
boolean sonA;
boolean sonR;
boolean sonV;
int counter;
void stop()
{
effect.close();
minim.stop();
super.stop();
}
void setup() {
size(640, 480); // Change size to 320 x 240 if too slow at 640 x 480
// Uses the default video input, see the reference if this causes an error
video = new Capture(this, width, height, 10);
noStroke();
smooth();
minim = new Minim(this);
// effect = minim.loadFile("sound.mp3");
minimA = new Minim(this);
soundA= minimA.loadFile("azul.mp3");
minimR = new Minim(this);
soundR= minimR.loadFile("rojo.mp3");
minimR = new Minim(this);
soundV= minimR.loadFile("verde.mp3");
sound = true;
sonA = true;
sonV = true;
sonR= true;
counter = 0;
}
void draw() {
if (video.available()) {
video.read();
image(video, 0, 0, width, height); // Draw the webcam video onto the screen
int colorXr = 0; // X-coordinate of the closest in color video pixel
int colorYr = 0; // Y-coordinate of the closest in color video pixel
int colorXg = 0; // X-coordinate of the closest in color video pixel
int colorYg = 0; // Y-coordinate of the closest in color video pixel
int colorXb = 0; // X-coordinate of the closest in color video pixel
int colorYb = 0; // Y-coordinate of the closest in color video pixel
float cercRojo = 180; //we set this to be abritrarily large, once program runs, the first pixel it scans will be set to this value
float cercAzul = 180;
float cercVerde = 180;
// Search for the closest in color pixel: For each row of pixels in the video image and
// for each pixel in the yth row, compute each pixel's index in the video
video.loadPixels();
int index = 0;
for (int y = 0; y < video.height; y++) {
for (int x = 0; x < video.width; x++) {
// Get the color stored in the pixel
color pixelValue = video.pixels[index];
// Determine the color of the pixel
float colorProximity = abs(red(pixelValue)-0)+abs(green(pixelValue)-255)+abs(blue(pixelValue)-0);
float colorProximity2 = abs(red(pixelValue)-255)+abs(green(pixelValue)-0)+abs(blue(pixelValue)-0);
float colorProximity3 = abs(red(pixelValue)-0)+abs(green(pixelValue)-0)+abs(blue(pixelValue)-255);
// If that value is closer in color value than any previous, then store the
// color proximity of that pixel, as well as its (x,y) location
if (colorProximity2 < cercRojo) {
// cercRojo = colorProximity2;
// cercRojo=cercRojo-10; //thoguht behind this is that it once it "locks" on to an object of color, it wont let go unless something a good bit better (closer in color) comes along
colorYr = y;// asignar posicion de circulo
colorXr = x;// asignar posicion circulo
}
if (colorProximity3 < cercAzul) {
//cercAzul = colorProximity3;
// cercAzul=cercAzul-10; //thoguht behind this is that it once it "locks" on to an object of color, it wont let go unless something a good bit better (closer in color) comes along
colorYb = y;// asignar posicion de circulo
colorXb = x;// asignar posicion circulo
}
if (colorProximity < cercVerde) {
// cercVerde = colorProximity;
//cercVerde=cercVerde-10; //thoguht behind this is that it once it "locks" on to an object of color, it wont let go unless something a good bit better (closer in color) comes along
colorYg = y;// asignar posicion de circulo
colorXg = x;// asignar posicion circulo
}
index++;
}//end for x
}// end for y
// Draw a large, yellow circle at the brightest pixel
if(colorXr!=0 ){
if(counter%20==0){
soundR.play();
sonR=true;
}
fill(255, 0, 0, 200);
ellipse(colorXr, colorYr, 200, 200);
}else{
if(sonR){
soundR.pause();
sonR=false;
}
}
if(colorXg!=0 ){
if(counter%20==0){
soundV.play();
sonV=true;
}
fill(0,255,0,200);
ellipse(colorXg,colorXg,100,100);
}else{
if(sonV){
soundV.pause();
sonV=false;
}
}
if(colorXb!=0 ){
if(counter%20==0){
soundA.play();
sonA=true;
}
fill(0,0,255,200);
ellipse(colorXb,colorXb,100,100);
}else{
if(sonA){
soundA.pause();
sonA=false;
}
}
if(counter==2000){
counter=0;
}
import processing.video.*;
Capture video;
Minim minim;
Minim minimA;
Minim minimV;
Minim minimR;
AudioPlayer effect;
AudioPlayer soundA;
AudioPlayer soundV;
AudioPlayer soundR;
boolean sound;
boolean sonA;
boolean sonR;
boolean sonV;
int counter;
void stop()
{
effect.close();
minim.stop();
super.stop();
}
void setup() {
size(640, 480); // Change size to 320 x 240 if too slow at 640 x 480
// Uses the default video input, see the reference if this causes an error
video = new Capture(this, width, height, 10);
noStroke();
smooth();
minim = new Minim(this);
// effect = minim.loadFile("sound.mp3");
minimA = new Minim(this);
soundA= minimA.loadFile("azul.mp3");
minimR = new Minim(this);
soundR= minimR.loadFile("rojo.mp3");
minimR = new Minim(this);
soundV= minimR.loadFile("verde.mp3");
sound = true;
sonA = true;
sonV = true;
sonR= true;
counter = 0;
}
void draw() {
if (video.available()) {
video.read();
image(video, 0, 0, width, height); // Draw the webcam video onto the screen
int colorXr = 0; // X-coordinate of the closest in color video pixel
int colorYr = 0; // Y-coordinate of the closest in color video pixel
int colorXg = 0; // X-coordinate of the closest in color video pixel
int colorYg = 0; // Y-coordinate of the closest in color video pixel
int colorXb = 0; // X-coordinate of the closest in color video pixel
int colorYb = 0; // Y-coordinate of the closest in color video pixel
float cercRojo = 180; //we set this to be abritrarily large, once program runs, the first pixel it scans will be set to this value
float cercAzul = 180;
float cercVerde = 180;
// Search for the closest in color pixel: For each row of pixels in the video image and
// for each pixel in the yth row, compute each pixel's index in the video
video.loadPixels();
int index = 0;
for (int y = 0; y < video.height; y++) {
for (int x = 0; x < video.width; x++) {
// Get the color stored in the pixel
color pixelValue = video.pixels[index];
// Determine the color of the pixel
float colorProximity = abs(red(pixelValue)-0)+abs(green(pixelValue)-255)+abs(blue(pixelValue)-0);
float colorProximity2 = abs(red(pixelValue)-255)+abs(green(pixelValue)-0)+abs(blue(pixelValue)-0);
float colorProximity3 = abs(red(pixelValue)-0)+abs(green(pixelValue)-0)+abs(blue(pixelValue)-255);
// If that value is closer in color value than any previous, then store the
// color proximity of that pixel, as well as its (x,y) location
if (colorProximity2 < cercRojo) {
// cercRojo = colorProximity2;
// cercRojo=cercRojo-10; //thoguht behind this is that it once it "locks" on to an object of color, it wont let go unless something a good bit better (closer in color) comes along
colorYr = y;// asignar posicion de circulo
colorXr = x;// asignar posicion circulo
}
if (colorProximity3 < cercAzul) {
//cercAzul = colorProximity3;
// cercAzul=cercAzul-10; //thoguht behind this is that it once it "locks" on to an object of color, it wont let go unless something a good bit better (closer in color) comes along
colorYb = y;// asignar posicion de circulo
colorXb = x;// asignar posicion circulo
}
if (colorProximity < cercVerde) {
// cercVerde = colorProximity;
//cercVerde=cercVerde-10; //thoguht behind this is that it once it "locks" on to an object of color, it wont let go unless something a good bit better (closer in color) comes along
colorYg = y;// asignar posicion de circulo
colorXg = x;// asignar posicion circulo
}
index++;
}//end for x
}// end for y
// Draw a large, yellow circle at the brightest pixel
if(colorXr!=0 ){
if(counter%20==0){
soundR.play();
sonR=true;
}
fill(255, 0, 0, 200);
ellipse(colorXr, colorYr, 200, 200);
}else{
if(sonR){
soundR.pause();
sonR=false;
}
}
if(colorXg!=0 ){
if(counter%20==0){
soundV.play();
sonV=true;
}
fill(0,255,0,200);
ellipse(colorXg,colorXg,100,100);
}else{
if(sonV){
soundV.pause();
sonV=false;
}
}
if(colorXb!=0 ){
if(counter%20==0){
soundA.play();
sonA=true;
}
fill(0,0,255,200);
ellipse(colorXb,colorXb,100,100);
}else{
if(sonA){
soundA.pause();
sonA=false;
}
}
if(counter==2000){
counter=0;
}
Suscribirse a:
Comentarios (Atom)
