Vertex will not fill (Processing 3)

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

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
// 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();
}


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
// 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 )

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();
}

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.

@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:

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.)

good find ( also wrong in my above code )

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);
}