We are about to switch to a new forum software. Until then we have removed the registration on this forum.
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
It seems to work with P2D/P3D, but not FX2D or the default renderer, thonk
Adding
curveTriangle.setFamily(PShape.PATH);
or changing line 13 tocurveTriangle = createShape(PShape.PATH);
fixes it for the JAVA2D renderer, but messes it up for the P2D renderer again.I am having similar problems, where everything looks good on screen, but not with PDF export.
I suggest you create a tix in github reporting your problem: https://github.com/processing/processing/issues
Kf
Just to point to this issue on github and also add my code that also shows the same problem:
https://github.com/processing/processing/issues/
(not sure if the issue creator is the same as this post creator)