We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSound,  Music Libraries › How can i make a new rectangle with another Sound
Page Index Toggle Pages: 1
How can i make a new rectangle with another Sound (Read 620 times)
How can i make a new rectangle with another Sound
May 9th, 2007, 9:46pm
 
Hello

I have this Code below and i would like to make a new rectangle (X<=20 and X>=40) and (Y<=0 and Y>=20). My Sound is called test2.aif. How can i handle this in my Code? Please can you held me. The code works for my rectangle but I need a second one.
---------------------------------

import pitaru.sonia_v2_9.*;


import processing.video.*;

// Variable for capture device
Capture video;
color trackColor;
Sample mySample;

void setup()
{
 size(720, 576);
 frameRate(24);
 colorMode(RGB,255,255,255,100);
 // Using the default capture device
 video = new Capture(this, 720, 576, 12);
 trackColor = color(255); // Start off tracking for white
 noFill();
 smooth();
 strokeWeight(4.0);
 stroke(0);
 Sonia.start(this);
 mySample = new Sample("test.aif");
}

void captureEvent(Capture camera)
{
 camera.read();
}

void draw()
{

 loadPixels();
 
 // Draw the video image on the background
 image(video,0,0);
 // Local variables to track the color
 float closestDiff = 500.0f;
 int closestX = 0;
 int closestY = 0;
 // Begin loop to walk through every pixel
 for ( int x = 0; x < video.width; x++) {
   for ( int y = 0; y < video.height; y++) {
     int loc = x + y*video.width;
     // What is current color
     color currentColor = video.pixels[loc];
     float r1 = red(currentColor); float g1 = green(currentColor); float b1 = blue(currentColor);
     float r2 = red(trackColor);   float g2 = green(trackColor);   float b2 = blue(trackColor);
     // Using euclidean distance to compare colors
     float d = dist(r1,g1,b1,r2,g2,b2);
     // If current color is more similar to tracked color than
     // closest color, save current location and current difference
     if (d < closestDiff) {
       closestDiff = d;
       closestX = x;
       closestY = y;
     }
   }
 }
 // Draw a circle at the tracked pixel
 ellipse(closestX,closestY,16,16);
 rect(0, 0, 20, 20);
 if ((closestX <= 20) && (closestY <= 20)) {
   if (mySample.isPlaying() == false) {
   mySample.play();
   }
 } else {
   mySample.stop();
 }
}

void mousePressed() {
 // Save color where the mouse is clicked in trackColor variable
 int loc = mouseX + mouseY*video.width;
 trackColor = video.pixels[loc];
}


public void stop(){
 Sonia.stop();
 super.stop();
}
Page Index Toggle Pages: 1