PShape vertice are not actually joined

Hi, I’m using PShape to draw an open path called pth. I add a certain number of vertex(int x, int y), then shape(pth) into a PDF to edit in Illustrator for path simplification and appearance rework. My problem: the resulting path is a collection of disconnected segments, i.e. the vertice aren’t actually joined.

There are Illustrator plugins which do that, but the actual project handles hundreds of these open paths and it takes litterally hours to join all the loose segments.

Is there a setting in the class that makes the vertice of a PShape actually joined?

do you endShape(CLOSE)? otherwise a snippet of the code would help :slight_smile:

Thanks for replying. I’m sorry but I got mixed up. There are projects where I use line(), others where I use PShape objects with method vertex(). This one uses calls to line() which were buried into some method. Bottom line is:

  • line() does not actually connect vertice, whereas vertex() does.

It seems shamefully obvious now that I’ve been thinking somewhat deeply about it, but I got confused by what the screen shows (connected segments) and what the vectors in the exported file actually are. For any beginner facing this kind of problem, I’ve made an example program to show how a collection of line() segments VS connected vertex() behave. Note that the resulting black squiggle is made using vertex() and the red one using line(). Their properties are otherwise identical on screen; to really understand the difference, you need a vector editing program to open the exported PDF, ungroup the objects and observe the (un)joining of segments.

// library needed to export PDFs
import processing.pdf.*;

// two-dimensional array to store vertice x/y pairs
int[][] the_vertice;

// PShape object
PShape the_shape;

void setup() {
  size(100, 100, P2D);

  // initialize vertice array
  the_vertice = new int[5][2];

  // radomize x/y pairs
  randomizeVrtx();

  // define PShape object
  the_shape = createShape();
  the_shape.beginShape();
  the_shape.stroke(0);
  the_shape.strokeWeight(1);
  the_shape.noFill();
  for (int i=0; i<the_vertice.length; i++) {
    for (int j=0; j<the_vertice[i].length; j++) {
      the_shape.vertex(the_vertice[i][0], the_vertice[i][1]);
    }
  }
  the_shape.endShape();

  // start logging graphics into PDF
  beginRecord(PDF, "vectorz.pdf");

  // draw shape using PShape object
  shape(the_shape);

  // randomize x/y pairs again
  randomizeVrtx();

  // set Processing's main canvas drawing properties
  stroke(255, 0, 0, 255);
  strokeWeight(1);
  noFill();

  // draw shape using Processing's line method
  for (int i=0; i<the_vertice.length-1; i++) {
    for (int j=0; j<the_vertice[i].length; j++) {
      line(the_vertice[i][0], the_vertice[i][1], the_vertice[i+1][0], the_vertice[i+1][1]);
    }
  }

  // stop logging to PDF and save file
  endRecord();
}

// method to randomize x/y pairs
void randomizeVrtx() {
  for (int i=0; i<the_vertice.length; i++) {
    for (int j=0; j<the_vertice[i].length; j++) {
      the_vertice[i][j] = int(random(70)+15.0);
    }
  }
}