# Creating inscribed circle & polygon loop

**URL:** <https://discourse.processing.org/t/creating-inscribed-circle-polygon-loop/14379>\
**Category:** Coding Questions\
**Created:** [October 2, 2019, 10:26pm UTC](https://discourse.processing.org/t/creating-inscribed-circle-polygon-loop/14379 "2019-10-02T22:26:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![fhop](https://avatars.discourse-cdn.com/v4/letter/f/9fc348/32.png) [@fhop](https://discourse.processing.org/u/fhop)\
**Post date:** [October 2, 2019, 10:26pm UTC](https://discourse.processing.org/t/creating-inscribed-circle-polygon-loop/14379/1 "2019-10-02T22:26:31Z")

</div>

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

* * *

```auto
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](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/8/88b442cb7f2fabacedf82d8ccc00288471b87282.png)

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [October 3, 2019, 1:57am UTC](https://discourse.processing.org/t/creating-inscribed-circle-polygon-loop/14379/2 "2019-10-03T01:57:50Z")

</div>

try to use

```auto
fill(color);

```

first.

```auto
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

---

<div class="post-metadata">

**Author:** ![fhop](https://avatars.discourse-cdn.com/v4/letter/f/9fc348/32.png) [@fhop](https://discourse.processing.org/u/fhop)\
**Post date:** [October 4, 2019, 9:59am UTC](https://discourse.processing.org/t/creating-inscribed-circle-polygon-loop/14379/3 "2019-10-04T09:59:39Z")

</div>

Thanks for the response!

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

```auto
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;
  } 
}

```

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [October 4, 2019, 10:27am UTC](https://discourse.processing.org/t/creating-inscribed-circle-polygon-loop/14379/4 "2019-10-04T10:27:18Z")

</div>

hm

 ![circles_polygon](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/7/7bc7bdca4092d3e9948fdd7ffff5baf5b6fdb2d5.png)

anyhow i just added fill(color)  
in front of

- vertex loop

and

- ellipse

---

<div class="post-metadata">

**Author:** ![fhop](https://avatars.discourse-cdn.com/v4/letter/f/9fc348/32.png) [@fhop](https://discourse.processing.org/u/fhop)\
**Post date:** [October 6, 2019, 8:33am UTC](https://discourse.processing.org/t/creating-inscribed-circle-polygon-loop/14379/5 "2019-10-06T08:33:11Z")

</div>

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