Hi
I’m trying to make a shape appear and start moving in an orbit whenever any of the shape above is clicked. So far i’m able to make shapes appear but i want a single shape to appear on a single click but as you can see after running the code that the shapes are appearing in groups. More over i want the previous shape to remain visible and orbiting when the next shape is clicked. Secondly please guide me on how to control the orbiting speed.
Here’s the code
type orbitDuration = 5*random(500,1500);
float orbitRad = 70;
float x,y;
int n=0,i=0,j=0,k=0;
void setup()
{
size(630,360);
background(251,255,71,0.97);
}
void draw()
{
background(251,255,71,0.97);
//making ellipse without border
noStroke();
fill(125);
ellipse(50, 44, 52, 52);
//making rectangle without border
noStroke();
fill(125);
rect(150,20,50,50);
noStroke();
fill(125);
triangle(300,20,260,65,340,65);
stroke(125);
strokeWeight(13);
line(400,20,440,55);
if ((mousePressed)&&(mouseX > 0) && (mouseX < 100)){
n++;
}
else if ((mousePressed)&&(mouseX > 120) && (mouseX < 200))
{
i++;
}
else if((mousePressed)&&(mouseX>259)&&(mouseX<341))
{
j++;
}
else if((mousePressed)&&(mouseX>399)&&(mouseX<441))
{
k++;
}
for (int p=0;p< n ; p++)
{
float ang = TWO_PI+(random(1,5)) * millis()/orbitDuration;
float x = cos(ang)*orbitRad;
float y = sin(ang)*orbitRad;
noStroke();
fill(148,148,142,255);
ellipse(x+300, y+200,15, 15);
}
for (int q=0; q<i; q++){
float ang = TWO_PI+(random(1,5)) * millis()/orbitDuration;
float x = cos(ang)*orbitRad;
float y = sin(ang)*orbitRad;
noStroke();
fill(20);
rect(x+300,y+200,10,10);
}
for (int t=0; t<j; t++){
float ang = TWO_PI+(random(1,5)) * millis()/orbitDuration;
float x = cos(ang)*orbitRad;
float y = sin(ang)*orbitRad;
noStroke();
fill(125);
triangle(x+300,y+200,x+295,y+208,x+305,y+208);
}
for (int l=0; l<k; l++){
float ang = TWO_PI+(random(1,5)) * millis()/orbitDuration;
float x = cos(ang)*orbitRad;
float y = sin(ang)*orbitRad;
stroke(50);
strokeWeight(3);
line(x+300,y+200,x+310,y+204);
}
}