AdamB
YaBB Newbies
Offline
Posts: 23
Selecting seperate objects to play different sound
Jan 15th , 2008, 2:11pm
Hey all, just a bit of help with a project i have. They are ten cylinders and i need each one to have a seperate sound. but i think the way it is laid out at the moment they are set as one since the colors are the same. So when the user clicks on the cylinder, the colour changes, but has its on specific colour to begin with. Thanks alot float rot = 0.0; int sideN = 100; void setup() { size(800, 400, P3D); noStroke(); } void draw() { background(0); lights(); for (int i = 0; i < 10; i++) { float xpos = ((i*70)+100); cylinder(25,200,sideN, xpos, height/2, i); } } void cylinder(float w, float h, int sides, float xstart, float ystart, int idx) { h = h+ystart; float angle; float[] x = new float[sides+1]; float[] z = new float[sides+1]; float maxx= 0; //get the x and z position on a circle for all the sides for(int i=0; i < x.length; i++){ angle = TWO_PI / (sides) * i; x[i] = (sin(angle) * w)+xstart; maxx = max(x[i], maxx); z[i] = cos(angle) *w; } if ((mouseX > xstart-25) && (mouseX < maxx+25)) { fill(0,255,0); println(idx); } else { fill(255,255,0); } //draw the top of the cylinder beginShape(TRIANGLE_FAN); vertex(xstart, -h/2, 0); for(int i=0; i < x.length; i++){ vertex(x[i], -h/2, z[i]); } endShape(); //draw the center of the cylinder beginShape(QUAD_STRIP); for(int i=0; i < x.length; i++){ vertex(x[i], -h/2, z[i]); vertex(x[i], h/2, z[i]); } endShape(); //draw the bottom of the cylinder beginShape(TRIANGLE_FAN); vertex(xstart, h/8, 0); for(int i=0; i < x.length; i++){ vertex(x[i], h/2, z[i]); } endShape(); } void keyPressed() { if (keyCode == UP) { sideN++; } if (keyCode == DOWN) { sideN--; } }