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);
}
}
void polygon(int sides, float radius){
float theta=0.0;
float x=0.0;
float y=0.0;
beginShape();
for (int i=0;i<sides;i++){
x=radius*cos(theta);
y=radius*sin(theta);
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

}Capture

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++) {
    x=radius*cos(theta);
    y=radius*sin(theta);
    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
}

please repair your code posting above,
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++) {
    x=radius*cos(theta);
    y=radius*sin(theta);
    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

anyhow i just added fill(color)
in front of

  • vertex loop

and

  • ellipse
2 Likes

was missing a set of curly brackets. thanks so much!!

1 Like