# PShape curveVertex() methods not working

**URL:** <https://discourse.processing.org/t/pshape-curvevertex-methods-not-working/42399>\
**Category:** Processing\
**Created:** [July 11, 2023, 7:08pm UTC](https://discourse.processing.org/t/pshape-curvevertex-methods-not-working/42399 "2023-07-11T19:08:26Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![thigmo](https://avatars.discourse-cdn.com/v4/letter/t/a87d85/32.png) [@thigmo](https://discourse.processing.org/u/thigmo)\
**Post date:** [July 11, 2023, 7:08pm UTC](https://discourse.processing.org/t/pshape-curvevertex-methods-not-working/42399/1 "2023-07-11T19:08:26Z")

</div>

I’m trying to use the PShape curveVertex() methods and they don’t seem to be working. I’m using Processing V4.2 on a Mac M2 Monterey. Javadocs for PShape indicates support for curveVertex(). I want to keep the PShape in a variable and reuse the shape.

In making the example I noticed that support for regular vertex() in PShape methods differ (they close the shape).

Any light on this subject would be appreciated!

Here’s the example and the code:

 ![Screen Shot 2023-07-11 at 2.08.01 PM](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/b/c/bc577845ab3b7cf4d1e7bfe17e4599e2d24e87cf.jpeg)

```auto
PVector [] coords = new PVector [4] ;
PShape sh;

void setup() {
  size(400, 400);

  sh = createShape();

  PVector pt1 = new PVector(10, 10);
  PVector pt2 = new PVector(100, 100);
  PVector pt3 = new PVector(200, 0);
  PVector pt4 = new PVector(300, 100);

  coords[0] = pt1;
  coords[1] = pt2;
  coords[2] = pt3;
  coords[3] = pt4;
}

void draw() {
  background(0);
  text("PShape Methods", 10, 10);
  // create shape with PShape methods
  sh.beginShape();
  sh.noFill();
  sh.strokeWeight(3);
  sh.stroke(255);
  // first curvevertex at beginning serves as control point
  sh.curveVertex(coords[0].x, coords[0].y);

  for (int j = 0; j<4; j++) {
    sh.curveVertex(coords[j].x, coords[j].y);
  }
  // last curvevertex at end for control point
  sh.curveVertex(coords[3].x, coords[3].y);
  sh.endShape();
  shape(sh);

  // Processing methods for drawing directly to canvas
  
  translate(0, 100);
  text("Processing Methods", 10, 10);
  noFill();
  strokeWeight(3);
  stroke(255);

  beginShape();
  // extra curvevertex at beginning serves as control point
  curveVertex(coords[0].x, coords[0].y);

  for (int j = 0; j<4; j++) {
    curveVertex(coords[j].x, coords[j].y);
  }

  // extra curvevertex at end for control point
  curveVertex(coords[3].x, coords[3].y);
  endShape();
}

```

---

<div class="post-metadata">

**Author:** ![thigmo](https://avatars.discourse-cdn.com/v4/letter/t/a87d85/32.png) [@thigmo](https://discourse.processing.org/u/thigmo)\
**Post date:** [July 11, 2023, 7:34pm UTC](https://discourse.processing.org/t/pshape-curvevertex-methods-not-working/42399/2 "2023-07-11T19:34:31Z")

</div>

OK I’ve solved one of the problems…

looks like createShape() has an optional constant parameter specifying type.

So adding PShape.PATH as the parameter, curveVertices start working!

```auto
  sh = createShape(PShape.PATH);

```

The remaining problem is to prevent it from closing the shape with a line from the end point to the starting point…

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [July 11, 2023, 7:42pm UTC](https://discourse.processing.org/t/pshape-curvevertex-methods-not-working/42399/3 "2023-07-11T19:42:16Z")

</div>

Hello @thigmo,

I added this to setup():

```auto
  size(400, 400, P2D);
  noLoop();

```

And it generated this:

![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/3/4/347db4ab2dc1b9e17bf9e79db8804f135771b43f.png)

Without the _noLoop()_ I had to add this to start of _draw()_:

`sh = createShape();`

Just a quick exploration…

`:)`

---

<div class="post-metadata">

**Author:** ![thigmo](https://avatars.discourse-cdn.com/v4/letter/t/a87d85/32.png) [@thigmo](https://discourse.processing.org/u/thigmo)\
**Post date:** [July 11, 2023, 8:16pm UTC](https://discourse.processing.org/t/pshape-curvevertex-methods-not-working/42399/4 "2023-07-11T20:16:55Z")

</div>

Thanks Glv!

The P2D renderer crashes (on the Mac) when it’s looping (with some odd fill artifacts). I’ll need to draw this on the fly so will need to get that working.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [July 11, 2023, 8:29pm UTC](https://discourse.processing.org/t/pshape-curvevertex-methods-not-working/42399/5 "2023-07-11T20:29:37Z")

</div>

essentially, this is about the difference between using `curveVertex` directly and saving it in a `PShape` first. Not the same result, especially on Mac, might be a bug.

this runs on WIN, same result for both, doesn’t close the shape:

```auto

PVector [] coords = {
  new PVector(10, 10),
  new PVector(100, 100),
  new PVector(200, 0),
  new PVector(300, 100)
};
PShape sh;

void setup() {
  size(1400, 700);

  // create shape with PShape methods
  sh = createShape(PShape.PATH);
  sh.beginShape();
  sh.noFill();
  sh.strokeWeight(3);
  sh.stroke(255, 0, 0);

  int[] indices = { 0, 0, 1, 2, 3, 3 };
  for (int j : indices) {
    sh.curveVertex(coords[j].x, coords[j].y);
  }
  sh.endShape();
}

void draw() {
  background(0);
  stroke(255);
  text("PShape Methods", 10, 10);

  shape(sh, 210, 10 );

  // Processing methods for drawing directly to canvas
  translate(0, 100);
  text("Processing Methods", 10, 10);
  noFill();
  strokeWeight(3);
  stroke(255);

  beginShape();
  // extra curvevertex at beginning serves as control point
  curveVertex(coords[0].x, coords[0].y);

  for (int j = 0; j<4; j++) {
    curveVertex(coords[j].x, coords[j].y);
  }

  // extra curvevertex at end for control point
  curveVertex(coords[3].x, coords[3].y);
  endShape();
}

```

---

<div class="post-metadata">

**Author:** ![thigmo](https://avatars.discourse-cdn.com/v4/letter/t/a87d85/32.png) [@thigmo](https://discourse.processing.org/u/thigmo)\
**Post date:** [July 11, 2023, 9:00pm UTC](https://discourse.processing.org/t/pshape-curvevertex-methods-not-working/42399/6 "2023-07-11T21:00:18Z")

</div>

Hm all very interesting!

Looking at both Glv and Chrisir explorations I learn a few things…

Mainly that the trouble seems to stem from redefining the vertices on a shape that has already been created. If you move the definition of the shape to the setup() - it works perfectly (I can’t do this because the shape is dynamic).

Or if you use createShape() again in the draw() loop, works perfectly. I wonder if there’s a performance or memory hit for putting the createShape in the draw() loop?

(by the way I found that there’s a way to explicitly specify that you want an open path, which probably is the default. But it still doesn’t work in this case)

```auto
sh.endShape(PShape.OPEN);

```

It looks like there’s a way to cycle through the pre-existing vertices and move them as seen here:

> **[PShape](https://processing.org/tutorials/pshape/#manipulating-the-vertices-of-a-pshape-in-real-time)**
>
> How to use the PShape class in Processing.

But that’s going to be hairy for my application because the number of vertices is constantly changing.

Thanks for the help you all!

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [July 11, 2023, 10:30pm UTC](https://discourse.processing.org/t/pshape-curvevertex-methods-not-working/42399/7 "2023-07-11T22:30:17Z")

</div>

> [@thigmo](#):
>
> I wonder if there’s a performance or memory hit for putting the createShape in the draw() loop?

Here is one tool you can use:  
[https://visualvm.github.io/?VisualVM\_2.1.5](https://visualvm.github.io/?VisualVM_2.1.5)

It has helped me with memory issues in the past.

`:)`

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [July 12, 2023, 10:21am UTC](https://discourse.processing.org/t/pshape-curvevertex-methods-not-working/42399/8 "2023-07-12T10:21:06Z")

</div>

> [@thigmo](#):
>
> But that’s going to be hairy for my application because the number of vertices is constantly changing.

Related topic:

[https://forum.processing.org/two/discussion/18064/remove-a-vertex-from-pshape.html](https://forum.processing.org/two/discussion/18064/remove-a-vertex-from-pshape.html)

`:)`
