bezierVertex does not behave as expected if stored as PShape

edited August 2017 in Questions about Code

Hi Everyone

I am trying to create some images that I need to export as vector files at some point. So I have been playing with PShape and bezierVertex() functions. I seem to either be doing something wrong, or maybe I found a bug.

I would expect the following code to draw two identical shapes, however, the shape that I save as a Pshape is not drawn correctly:

//Vertex does not store beziers correctly.

int triangleCurve = -15; //play with this variable to explore the problem

int triangleWidth = 100;   
int triangleHeight = 100;

PShape curveTriangle;

void setup() {
  size(300, 150);
  //I'm creating a shape here and storing it as 'curveTriangle' 
  curveTriangle = createShape();
  curveTriangle.beginShape();
  curveTriangle.fill(200, 40, 40); 
  curveTriangle.vertex(triangleWidth, 0);
  curveTriangle.bezierVertex(triangleWidth/2, triangleHeight/4+triangleCurve, triangleWidth/2, triangleHeight/4-triangleCurve, 0, triangleHeight/2);
  curveTriangle.bezierVertex(triangleWidth/2, (triangleHeight/4)*3+triangleCurve, triangleWidth/2, (triangleHeight/4)*3-triangleCurve, triangleWidth, triangleHeight);
  curveTriangle.endShape();
}

void draw() {
  //I draw the 'curveTriangle twice. First (left) by placing the shape I created before. This is not what I need
  //On the right is the way it looks if I do not store it in a PShape. This is what I need.

  fill(0, 0, 255); //this does nothing

  shape(curveTriangle, 20, 20); //this one does not display correctly

  translate(130, 20); // just moving it over

  fill(40, 200, 40);
  beginShape(); //this shape is created using exactly the same instructions as the other one. It displays correctly
  vertex(triangleWidth, 0);
  bezierVertex(triangleWidth/2, triangleHeight/4+triangleCurve, triangleWidth/2, triangleHeight/4-triangleCurve, 0, triangleHeight/2);
  bezierVertex(triangleWidth/2, (triangleHeight/4)*3+triangleCurve, triangleWidth/2, (triangleHeight/4)*3-triangleCurve, triangleWidth, triangleHeight);
  endShape();
}

Am I misunderstanding how these functions are used or is this a legit bug?

Below is an image of what I see when I run this code:

Answers

Sign In or Register to comment.