# Vertex will not fill (Processing 3)

**URL:** https://discourse.processing.org/t/vertex-will-not-fill-processing-3/6013
**Category:** Coding Questions
**Created:** [November 27, 2018, 10:09pm UTC](https://discourse.processing.org/t/vertex-will-not-fill-processing-3/6013 "2018-11-27T22:09:17Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Mr\_Dumpling](https://avatars.discourse-cdn.com/v4/letter/m/b487fb/32.png) [@Mr\_Dumpling](https://discourse.processing.org/u/Mr_Dumpling)
#### Post date: [November 27, 2018, 10:09pm UTC](https://discourse.processing.org/t/vertex-will-not-fill-processing-3/6013/1 "2018-11-27T22:09:17Z")

</div>

So I have been trying to make a circle generator using vertexes, as I want to be able to use them in contours. However I have only been able to get points to show up, lines will not connect, and simply make dots every other point, and I would like to be able to see the circle without points, so I am using fill. However no amount of fill seems to be working, no matter when I place the code, sample code:

> void setup() {  
> size(800, 600);  
> fill(50, 100, 150);  
> beginShape(POINTS);  
> vertexCircle(width/2, height/2, 100, 0, 360, 360);  
> endShape(CLOSE);  
> }
> 
> void draw() {  
> }
> 
> void vertexCircle(int x, int y, int diameter, int arcStrt, int arcStp, int arcPntAmt) {  
> pushMatrix();  
> translate(x, y);  
> rotate (arcStrt);  
> for (int vertexAmt = 0; vertexAmt \<= arcPntAmt; vertexAmt += 1) {  
> vertex(0, 0 + diameter);  
> rotate ( radians (360-arcStp/arcPntAmt));  
> }  
> popMatrix();  
> }

Please note I am fairly new to coding in processing, so I may have made a simple stupid mistake =P

---

<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: [November 28, 2018, 3:22am UTC](https://discourse.processing.org/t/vertex-will-not-fill-processing-3/6013/3 "2018-11-28T03:22:33Z")

</div>

i think it is not a question of shape not closing and not filling,  
problem is that vertex needs absolut positioning ,  
so the created " vertex list " possibly just not see the rotate.  
so i try in the same loop

- calculate the absolute positions for vertex ( sin/cos )
- still use relative positioning for other objects rotate for line & circles

> **test**
>
> ```auto
> // https://discourse.processing.org/t/vertex-will-not-fill-processing-3/6013
> 
> boolean dbug = true; // use: if ( dbug ) println("");
> boolean rottest = true;
> 
> void setup() {
> size(500, 500);
> vertexCircle(width/2, height/2, 100, 30, 120, 5);
> }
> 
> void draw() {
> }
> 
> void vertexCircle(int x, int y, int diameter, int arcStrt, int arcStp, int arcPntAmt) {
> float anglestep = radians ((arcStp-arcStrt)/float(arcPntAmt));
> if ( dbug ) println("angle: "+anglestep);
> fill(0, 200, 0);
> stroke(200, 0, 0);
> pushMatrix();
> translate(x, y);
> rotate (radians(arcStrt));
> beginShape();
> vertex(0, 0);
> for (int i = 0; i <= arcPntAmt; i++) {
> float posx = diameter*cos(i*anglestep);
> float posy = diameter*sin(i*anglestep);
> if ( dbug ) println("point: x: "+posx+" y: "+posy);
> vertex(posx, posy); // vertex needs absolut positions
> if ( dbug ) println("i "+i);
> if (rottest) {
> rotate(anglestep); // still can use relative positioning
> ellipse(0, diameter+10, 3, 3); 
> line(0, diameter, 0, diameter+10); // to show something
> }
> }
> vertex(0, 0);
> endShape();
> popMatrix();
> }
> 
> ```

 ![snap-020](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/4/463727d66cd02417d73e6e84b2dcdc1cf1a8e796.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: [November 28, 2018, 4:25am UTC](https://discourse.processing.org/t/vertex-will-not-fill-processing-3/6013/4 "2018-11-28T04:25:15Z")

</div>

i wanted to be the “smartass” and suggest that it might be good if we can check  
on the shape we created ( like print its vertexes )

like you could find that you made a shape ( and closed and fill it )  
BUT all at / the same / one point

well i just found that that is indeed possible,  
but i needed to create a (named) shape  
and it shows that the vectors are pure, not contain the translate or rotate…

> **test v03**
>
> ```auto
> // https://discourse.processing.org/t/vertex-will-not-fill-processing-3/6013
> 
> // v02 vertex as shape
> // v03 diagnostic vertex
> 
> PShape s;
> boolean dbug = true; // use: if ( dbug ) println("");
> boolean rottest = true;
> 
> void setup() {
> size(500, 500);
> vertexCircle(width/2, height/2, 100, 30, 120, 5); // now creates shape s AND shows it
> }
> 
> void draw() {
> }
> 
> void vertexCircle(int x, int y, int diameter, int arcStrt, int arcStp, int arcPntAmt) {
> float anglestep = radians ((arcStp-arcStrt)/float(arcPntAmt));
> if ( dbug ) println("angle: "+anglestep);
> fill(0, 200, 0);
> stroke(200, 0, 0);
> pushMatrix();
> translate(x, y);
> rotate (radians(arcStrt));
> s = createShape();
> s.beginShape();
> s.vertex(0, 0);
> for (int i = 0; i <= arcPntAmt; i++) {
> float posx = diameter*cos(i*anglestep);
> float posy = diameter*sin(i*anglestep);
> if ( dbug ) println("point: x: "+posx+" y: "+posy);
> s.vertex(posx, posy); // vertex needs absolut positions
> if ( dbug ) println("i "+i);
> if (rottest) {
> rotate(anglestep); // still can use relative positioning
> ellipse(0, diameter+10, 3, 3); 
> line(0, diameter, 0, diameter+10); // to show something
> }
> }
> s.vertex(0, 0);
> s.endShape();
> // v 03 try readback shape
> if ( dbug ) println(" check vertex content");
> for (int i=0; i < s.getVertexCount(); i++) {
> if ( dbug ) println("vx: "+s.getVertex(i).x+" vy: "+s.getVertex(i).y);
> }
> shape(s,0,0);
> popMatrix();
> }
> 
> ```

now use that trick on your code:  
( still shows no shape, but prints out WHY )

```auto
PShape s;

void setup() {
  size(800, 600);
  fill(50, 100, 150);
  s = createShape();

  s.beginShape(POINTS);
  vertexCircle(width/2, height/2, 100, 0, 360, 360);
  s.endShape(CLOSE);
  shape(s, 0, 0);
  
  println(" check vertex content");
  for (int i=0; i < s.getVertexCount(); i++) {
    println("vx: "+s.getVertex(i).x+" vy: "+s.getVertex(i).y);
  }
  
}

void draw() {
}

void vertexCircle(int x, int y, int diameter, int arcStrt, int arcStp, int arcPntAmt) {
  pushMatrix();
  translate(x, y);
  rotate (arcStrt);
  for (int vertexAmt = 0; vertexAmt <= arcPntAmt; vertexAmt += 1) {
    s.vertex(0, 0 + diameter);
    rotate ( radians (360-arcStp/arcPntAmt));
  }
  popMatrix();
}

```

---

<div class="post-metadata">

### Author: ![Mr\_Dumpling](https://avatars.discourse-cdn.com/v4/letter/m/b487fb/32.png) [@Mr\_Dumpling](https://discourse.processing.org/u/Mr_Dumpling)
#### Post date: [November 28, 2018, 1:54pm UTC](https://discourse.processing.org/t/vertex-will-not-fill-processing-3/6013/5 "2018-11-28T13:54:51Z")

</div>

I think it may have to do with the order and rotation, gonna play with it a bit, I’ll post an update if I get it to work.

---

<div class="post-metadata">

### Author: ![Whahahahaha](https://avatars.discourse-cdn.com/v4/letter/w/3be4f8/32.png) [@Whahahahaha](https://discourse.processing.org/u/Whahahahaha)
#### Post date: [November 28, 2018, 2:52pm UTC](https://discourse.processing.org/t/vertex-will-not-fill-processing-3/6013/6 "2018-11-28T14:52:05Z")

</div>

@Mr_Dumpling what’s wrong with not using rotate()?  
like @kll already gave in his code, with cos and sin it works and there’s no point in using rotate right?

it can be as easy as this:

```auto
void setup() {
  size(500, 500);
  vertexCircle(width/2, height/2, 200, 0, 180, 10);
}
void draw() {
}

void vertexCircle(int x, int y, int diameter, int start, int stop, int amount) {
  translate(x, y);
  beginShape();
  vertex(0, 0);
  for (float i = start; i <= stop; i+= (stop-start)/amount) {
    float posx = diameter*cos(radians(i));
    float posy = diameter*sin(radians(i));
    vertex(posx, posy);
  }
  vertex(0, 0);
  endShape();
}

```

\*edit: somehow “i” gets rounded or gets extra decimals, which creates a gap so it won’t reach the stop-angle. kind of fixable by saying i \<= stop+1… though not the best solution i guess (by going 360 degrees in 50 steps creates steps op 7.2 degrees, but somehow the last step is at the angle of 352.8008, which is too much to add another 7.2 without going above the 360.)

---

<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: [November 28, 2018, 3:47pm UTC](https://discourse.processing.org/t/vertex-will-not-fill-processing-3/6013/7 "2018-11-28T15:47:23Z")

</div>

> [@Whahahahaha](#):
>
> somehow “i” gets rounded or gets extra decimals, which creates a gap so it won’t reach the stop-angle. kind of fixable by saying i \<= stop+1… though not the best solution i guess (by going 360 degrees in 50 steps creates steps op 7.2 degrees, but somehow the last step is at the angle of 352.8008, which is too much to add another 7.2 without going above the 360.

good find ( also wrong in my above code )

```auto
int start =0;
int stop = 360;
int amount = 7;

//for (float i = start; i <= stop; i+= (stop-start)/amount) {
  /*
i: 0.0
i: 51.0
i: 102.0
i: 153.0
i: 204.0
i: 255.0
i: 306.0
i: 357.0
*/

for (float i = start; i <= stop; i+= (stop-start)/float(amount)) {
/*
i: 0.0
i: 51.42857
i: 102.85714
i: 154.2857
i: 205.71428
i: 257.14285
i: 308.5714
i: 359.99997
*/
  println("i: "+i);
}

```
