When I use link(), it launches the browser page six times per click. Is there a way to launch the URL only once without killing the draw loop?
If it helps, here is the relevant methods (animate() is called in the draw loop):
void animate(int turn){
//println(turn);
// color according to hex list
noStroke();
color t = color(color_array[turn]);
fill(t);
// draw ball according to bag weight
ellipse(b[turn].b_xpos, b[turn].b_ypos, b[turn].b_weight, b[turn].b_weight);
// write folder number on ball
if (mouseOver(turn) == true){
stroke(100,100,100);
fill(100,100,100);
text(turn, b[turn].b_xpos, b[turn].b_ypos);
b[turn].b_xpos = b[turn].b_xpos + 0.1*(vel(turn)); // slow it down to make it readable
b[turn].b_ypos = b[turn].b_ypos + 0.1*(vel(turn));
if (mousePressed){
if(mouseButton == LEFT){
b[turn].b_vx = random(-2,2);
b[turn].b_vy = random(-2,2);
}
if(mouseButton == RIGHT){
link(makeURL(turn));
// noLoop(); // kills the whole draw loop
}
}
}
else {
b[turn].b_xpos = b[turn].b_xpos + b[turn].b_vx; // move the ball normally
b[turn].b_ypos = b[turn].b_ypos + b[turn].b_vy;
}
// bounce balls off walls
if (b[turn].b_ypos > height-(b[turn].b_weight/2) || b[turn].b_ypos < 0 + b[turn].b_weight/2){
b[turn].b_vy = b[turn].b_vy*(-1.0);
}
if (b[turn].b_xpos > width- (b[turn].b_weight/2) || b[turn].b_xpos < 0 + (b[turn].b_weight/2)){
b[turn].b_vx = b[turn].b_vx*(-1.0);
}
}
// looks for the mouse at each ball
boolean mouseOver(int turn){
if (mouseX >= b[turn].b_xpos - b[turn].b_weight/2 && mouseX <= b[turn].b_xpos + b[turn].b_weight/2 &&
mouseY >= (b[turn].b_ypos - b[turn].b_weight/2) && mouseY <= (b[turn].b_ypos + b[turn].b_weight/2)){
return true;
}
else return false;
}