# Creating inscribed circle & polygon loop

Hi I would like to create a loop with red circles and blue polygons but when I do my loop only the circles in the center are red the rest are blue. I know I need to put the ellipse & polygon together in a loop but have no idea how, any help would be appreciated!

reference image attached

Thanks

``````void setup(){
size(500,500);
background(255);
//noStroke();
translate(width/2,height/2);
for (int j=0;j<8;j++){
fill(#35DEE3);
polygon(8,450.0);

scale(0.75);
}
}
float theta=0.0;
float x=0.0;
float y=0.0;
beginShape();
for (int i=0;i<sides;i++){
rotate(PI/7.0);
vertex(x,y);
theta=theta+2*PI/sides;
}
endShape(CLOSE);

float scaleFactor = 0.74;
float side = 830;
for (int i=0;i<5;i++){
ellipse(0,0,side,side);
fill(#E3354C);
side = side*scaleFactor;
} //end polygon
``````

} 1 Like

try to use

``````fill(color);
``````

first.

``````void polygon(int sides, float radius) {
float theta=0.0;
float x=0.0;
float y=0.0;
beginShape();
fill(200,0,200);
for (int i=0; i<sides; i++) {
rotate(PI/7.0);
vertex(x, y);
theta=theta+2*PI/sides;
}
endShape(CLOSE);

float scaleFactor = 0.74;
float side = 830;
for (int i=0; i<5; i++) {
fill(0,0,200);
ellipse(0, 0, side, side);
//fill(#E3354C);
side = side*scaleFactor;
} //end polygon
}
``````

using the
`</> Preformatted text` button from the editor menu

2 Likes

Thanks for the response!

When I put that into my code all i can see is circles no polygons anymore?

``````void setup(){
size(500,500);
background(255);
//noStroke();
translate(width/2,height/2);
for (int j=0;j<8;j++)
fill(#35DEE3);
polygon(8,450.0);}

void polygon(int sides, float radius) {
float theta=0.0;
float x=0.0;
float y=0.0;
beginShape();
fill(200,0,200);
for (int i=0; i<sides; i++) {
rotate(PI/7.0);
vertex(x, y);
theta=theta+2*PI/sides;
}
endShape(CLOSE);

float scaleFactor = 0.74;
float side = 830;
for (int i=0; i<5; i++) {
fill(0,0,200);
ellipse(0, 0, side, side);
//fill(#E3354C);
side = side*scaleFactor;
}
}
``````

hm