I know I could use arrays to make this easier but I have never used arrays before ...
in
Programming Questions
•
2 years ago
I know the following code could be made more simply with maybe one or two arrays ... how do i go about approaching simplifying this code to enable it to be more effective code.
void setup() {
size(500,500);
}
void draw() {
background(125);
float xpos = mouseX;
float ypos = mouseY;
float xpos2 = mouseX*1.5;
float ypos2 = mouseY*1.5;
float xpos3 = mouseX*1.25;
float ypos3 = mouseY*1.25;
float circle_dim = 50;
ypos = constrain(ypos, 50,450);
xpos = constrain(xpos, 50,450);
xpos2 = constrain(xpos2, 150,350);
ypos2 = constrain(ypos2, 150,350);
xpos3 = constrain(xpos3, 200, 300);
ypos3 = constrain(ypos3, 200, 300);
//outer circles
ellipse(50, ypos, circle_dim, circle_dim);
ellipse(50, height - ypos, 50, 50);
ellipse(xpos, 50, 50,50);
ellipse(width - xpos, 50, 50, 50);
ellipse(450, ypos, 50, 50);
ellipse(450, height - ypos, 50, 50);
ellipse(xpos, 450, 50, 50);
ellipse(width - xpos, 450, 50, 50);
// inset one
ellipse(150,xpos2, 100, 100);
ellipse(150, width - xpos2, 100,100);
ellipse(ypos2,150, 100,100);
ellipse(width - ypos2, 150, 100,100);
ellipse(350, xpos2, 100, 100);
ellipse(350, height - xpos2, 100,100);
ellipse(ypos2, 350, 100,100);
ellipse(width - ypos2, 350, 100, 100);
ellipse(ypos3, 250, 25, 25);
ellipse(xpos3, 250, 25, 25);
ellipse( 250,height - ypos3, 25, 25);
ellipse(250, width - xpos3, 25, 25);
}
void setup() {
size(500,500);
}
void draw() {
background(125);
float xpos = mouseX;
float ypos = mouseY;
float xpos2 = mouseX*1.5;
float ypos2 = mouseY*1.5;
float xpos3 = mouseX*1.25;
float ypos3 = mouseY*1.25;
float circle_dim = 50;
ypos = constrain(ypos, 50,450);
xpos = constrain(xpos, 50,450);
xpos2 = constrain(xpos2, 150,350);
ypos2 = constrain(ypos2, 150,350);
xpos3 = constrain(xpos3, 200, 300);
ypos3 = constrain(ypos3, 200, 300);
//outer circles
ellipse(50, ypos, circle_dim, circle_dim);
ellipse(50, height - ypos, 50, 50);
ellipse(xpos, 50, 50,50);
ellipse(width - xpos, 50, 50, 50);
ellipse(450, ypos, 50, 50);
ellipse(450, height - ypos, 50, 50);
ellipse(xpos, 450, 50, 50);
ellipse(width - xpos, 450, 50, 50);
// inset one
ellipse(150,xpos2, 100, 100);
ellipse(150, width - xpos2, 100,100);
ellipse(ypos2,150, 100,100);
ellipse(width - ypos2, 150, 100,100);
ellipse(350, xpos2, 100, 100);
ellipse(350, height - xpos2, 100,100);
ellipse(ypos2, 350, 100,100);
ellipse(width - ypos2, 350, 100, 100);
ellipse(ypos3, 250, 25, 25);
ellipse(xpos3, 250, 25, 25);
ellipse( 250,height - ypos3, 25, 25);
ellipse(250, width - xpos3, 25, 25);
}
1