Smooth close curveVertex shape

hi,
how to smooth close a curveVertex shape, like this:
thnx!

void setup() {
  size(200,200);
  smooth();
  noFill();
  strokeWeight(1);
}


void draw() {
  curves(0,100,  100,0, 200,100, 100,200, 0,100);
}


void curves(int _x1, int _y1, int _x2, int _y2, int _x3, int _y3, int _x4, int _y4, int _x5, int _y5) {
  beginShape();
  curveVertex(_x5, _y5);
  curveVertex(_x1, _y1);
  curveVertex(_x2, _y2);
  curveVertex(_x3, _y3);
  curveVertex(_x4, _y4);
  curveVertex(_x5, _y5);
  curveVertex(_x1, _y1);
  curveVertex(_x2, _y2);
  endShape(CLOSE);
}
1 Like

looks like your point 5 ( as is at point1 )
is what you have to do to close a rectangle, good,
but do it in the function and not in the call

int x = 100, y = 100, w = 40, h = 80;
boolean showP = false;

void setup() {
  size(300,300);
  noFill();
  strokeWeight(3);
}

void draw() {
  background(200,200,0);
  curves(x,y,x+w,y,x+w,y+h,x,y+h);
}

void curves(int _x1, int _y1, int _x2, int _y2, int _x3, int _y3, int _x4, int _y4) {
  beginShape();
  curveVertex(_x4, _y4);  // control point
  curveVertex(_x1, _y1);
  if ( showP ) circle(_x1, _y1,3); 
  curveVertex(_x2, _y2);
  if ( showP ) circle(_x2, _y2,3); 
  curveVertex(_x3, _y3);
  if ( showP ) circle(_x3, _y3,3); 
  curveVertex(_x4, _y4);
  if ( showP ) circle(_x4, _y4,3); 
  curveVertex(_x1, _y1);
  curveVertex(_x2, _y2);  // control point   
  endShape();
}


or see it this way:

int x = 100,y = 100,w = 40,h = 80;
boolean showP = false;

void setup() {
  size(300,300);
  noFill();
  strokeWeight(3);
}

void draw() {
  background(200,200,0);
  curve_vertex_rect(x,y,w,h);
}


void curve_vertex_rect(int _x, int _y, int _w, int _h) {
  int _x1 = _x;
  int _y1 = _y;
  int _x2 = _x1+_w;
  int _y2 = _y1;
  int _x3 = _x1+_w;
  int _y3 = _y1+_h;
  int _x4 = _x1;
  int _y4 = _y1+_h;
  
  beginShape();
  curveVertex(_x4, _y4);  // control point
  curveVertex(_x1, _y1);
  if ( showP ) circle(_x1, _y1,3); 
  curveVertex(_x2, _y2);
  if ( showP ) circle(_x2, _y2,3); 
  curveVertex(_x3, _y3);
  if ( showP ) circle(_x3, _y3,3); 
  curveVertex(_x4, _y4);
  if ( showP ) circle(_x4, _y4,3); 
  curveVertex(_x1, _y1);
  curveVertex(_x2, _y2);  // control point   
  endShape();
}

1 Like

thank you so much for this comprehensive help!:slight_smile:

1 Like