Hi
i’m trying to make the shapes move in an orbit below whenever any of the shapes is clicked above. It’s pretty much happening if you run the code below. The problem is that when ever a new shape is clicked the previous shape vanishes. I want the new shape to be added into the orbit while the previous shape keeps orbiting and i don’t know how to do that. Please help.
int constant = 250;
float[] angle1 = new float[100];
int scalar = 100;
float speed = 0.05;
float[] increment=new float[100];
int limit=0;
int limit1=0;
int limit2=0;
int limit3=0;
int limit4=0;
int num;
void setup() {
size(1350, 450);
smooth();
}
void mouseClicked()
{
if ((mouseX>520) && (mouseX<550)&&(mouseY>28)&&(mouseY<53)) {
num=1;
limit1++;
}
if ((mouseX>588) && (mouseX<612)&&(mouseY>28)&&(mouseY<53)) {
num=2;
limit2++;
}
if ((mouseX>652) && (mouseX<686)&&(mouseY>28)&&(mouseY<53)) {
num=3;
limit3++;
}
if ((mouseX>720) && (mouseX<749)&&(mouseY>28)&&(mouseY<52)) {
num=4;
limit4++;
}
increment[limit] = random(1, 200);
limit++;
}
void draw() {
background(255);
//Navigation Buttons
noStroke();
fill(255);
ellipse(650, 250, 300, 295);
noStroke();
fill(224, 224, 224);
ellipse(537, 41, 25, 24);
noStroke();
fill(224, 224, 224);
rect(590, 31, 20, 20);
noStroke();
fill(224, 224, 224);
triangle(670, 28, 655, 50, 685, 50);
stroke(224, 224, 224);
strokeWeight(10);
line(725, 32, 743, 43);
shape obj=new shape();
if (num==1) {
obj.createCircle();
}
if (num==2) {
obj.createSquare();
}
if (num==3) {
obj.createTriangle();
}
if (num==4) {
obj.createLine();
}
}
public class shape {
public
void createSquare() {
for (int i=0; i<=limit2; i++)
{
float x = constant + sin(angle1[i]) * scalar;
float y = constant + cos(angle1[i]) * scalar;
noStroke();
fill(33, 150, 243);
rect(x+400, y+25, 12, 12);
angle1[i] = angle1[i] + (speed+increment[limit]);
}
}
void createTriangle() {
for (int i=0; i<=limit3; i++)
{
float x = constant + sin(angle1[i]) * scalar;
float y = constant + cos(angle1[i]) * scalar;
noStroke();
fill(139, 195, 74);
triangle(x+400, y+20, x+390, y+33, x+410, y+33);
angle1[i] = angle1[i] + (speed+increment[limit]);
}
}
void createLine() {
for (int i=0; i<=limit4; i++)
{
float x = constant + sin(angle1[i]) * scalar;
float y = constant + cos(angle1[i]) * scalar;
stroke(255, 193, 7);
strokeWeight(3);
line(x+400, y+25, x+415, y+28);
angle1[i] = angle1[i] + (speed+increment[limit]);
}
}
void createCircle()
{
for (int i=0; i<=limit1; i++)
{
float x = constant + sin(angle1[i]) * scalar;
float y = constant + cos(angle1[i]) * scalar;
noStroke();
fill(244, 67, 54);
ellipse(x+400, y+25, 18, 18);
angle1[i] = angle1[i] + (speed+increment[limit]);
}
}
}