How to form a smooth loop using curve()?

Hi,

Currently, the start and end points of my shape, which is formed using curve vertices, connect up in a pointy way. Is there any way to have them connect in the same smooth and kind of rounded way as they are like in the other points?

Here's an image of what it looks like currently and below is the code (as you can see, I tried making the first and last points equal to the two control points...).

void setup() {
  size(600, 600);
  smooth();
  ellipseMode(CENTER);
}

void draw() {
  background(0);

  curves(100, 330, 100, 330, 330, 200, 449, 232, 416, 416, 200, 520, 100, 330, 100, 330);

  noLoop();
}

void curves(int _xA, int _yA, int _x1, int _y1, int _x2, int _y2, int _x3, int _y3, int _x4, int _y4, int _x5, int _y5, int _x6, int _y6, int _xZ, int _yZ) {
  noFill();
  stroke(255, 100, 0);
  strokeWeight(5);

  beginShape();
  curveVertex(_xA, _yA);
  curveVertex(_x1, _y1);
  curveVertex(_x2, _y2);
  curveVertex(_x3, _y3);
  curveVertex(_x4, _y4);
  curveVertex(_x5, _y5);
  curveVertex(_x6, _y6);
  curveVertex(_xZ, _yZ);
  endShape();
}
Tagged:

Answers

  • edited February 2016 Answer ✓

    Try this?

    void curves(int _x1, int _y1, int _x2, int _y2, int _x3, int _y3, int _x4, int _y4, int _x5, int _y5) {
      noFill();
      stroke(255, 100, 0);
      strokeWeight(5);
    
      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();
    }
    
  • @Bird yes, that works, thank you.

Sign In or Register to comment.