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 & HelpSyntax Questions › How do I activate a sound.wav in an arc shape?
Page Index Toggle Pages: 1
How do I activate a sound.wav in an arc shape?? (Read 378 times)
How do I activate a sound.wav in an arc shape??
Dec 9th, 2009, 6:36pm
 
Hi there,

I am having trouble fixing my code to make it run properly. I have been working with atan2() to try and figure out when the mouse clicks and drags on a specific segment of the ellipse in the center of the screen then a sound will play. Can anyone help me Im very lost as what to do. the code is below:



import ddf.minim.signals.*;
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;

int diameter = 300;

Minim minim;
Button[] buttons = new Button[20];

void setup()
{
 size(500, 500);
 smooth();
 noStroke();
 
 minim = new Minim(this);
 float num = 0;
 
 for(int i=0; i<buttons.length; i++) {
   buttons[i] = new Button();
   buttons[i].start = num;
   buttons[i].end = num + radians(360/buttons.length);
   buttons[i].colour = (i * 10);
   buttons[i].sound = minim.loadSnippet(i%20+".wav");
   num += radians(360/buttons.length);
 }
}

void draw()
{
 background(150);
 int i = 0;

 while(i < buttons.length)
 {
  buttons[i].display();        
 }
}


void mouseDragged()
{
 for(int i=0; i<20; i++){
   if(!buttons[i].sound.isPlaying())
   {
     buttons[i].play();
   }
 }
}

class Button
{
 float start;
 float end;
 color colour;
 AudioSnippet sound;
 
 void display() {
   fill(colour);
   arc(width/2, height/2, diameter, diameter, start, end);
 }
 
 void play() {
   int i = 0;
   float currAng = atan2(width/2 - mouseY,height/2 - mouseX);
   float sectAmount = (2*PI)/20;
   while(i<20)
   {
    if(currAng>(i*sectAmount) && currAng < ((i + 1)%20)*sectAmount && dist(mouseX,mouseY,constrain(mouseX,start, currAng),constrain(mouseY,end,currAng))<10)
   {
     sound.loop(0);
   }
     i++;
   }
 }
}
Page Index Toggle Pages: 1