We are about to switch to a new forum software. Until then we have removed the registration on this forum.
This might be silly, but i can't tell why this work works with pg.vertex but the same code doesn't work with pg.curveVertex
This works:
PShape pg = createShape();
translate(0, height);
scale(1, -1);
size(400, 400);
pg.beginShape();
pg.noFill();
for (int i=1; i<=400; i=i+10) {
pg.vertex(i,sq(i*2/5)/10);
}
pg.endShape();
shape(pg);
This doesn't work:
PShape pg = createShape();
translate(0, height);
scale(1, -1);
size(400, 400);
pg.beginShape();
pg.noFill();
for (int i=1; i<=400; i=i+10) {
pg.curveVertex(i,sq(i*2/5)/10);
}
pg.endShape();
shape(pg);
but, oddly enough, if you remove pg. it works
PShape pg = createShape();
translate(0, height);
scale(1, -1);
size(400, 400);
beginShape();
noFill();
for (int i=1; i<=400; i=i+10) {
curveVertex(i,sq(i*2/5)/10);
}
endShape();
shape(pg);
Answers
The PShape with the pg.curveVertex() will show correctly if you choose P2D mode.
Don’t know why it did not appear on default mode (JAVA2D)? But I noticed that every examples of createShape() in the reference file are done in P2D mode to. I have tested in version 2.2.1 and only P2D is compiled correctly. In version 3+, I tested with the 3 modes : P2D, JAVA2D, FX2D. No problem to compiled, but very different rendering on each case. Noticed that FX2D is flipped upside down (which have already been reported).
You can test it with this code :
Just uncommented the command size() of the rendering mode you want to test (and commented the two others).
Thanks for you answer!
Sadly my computer doesn't support P2D so i can only test with JAVA2D. I seen in your example you've used vertex. This was in fact your intent, to test PShape rendering in general?
Here i can only render with the default mode, where i get the result from the middle image you've posted.
I need to draw curveVertex in a PGraphics using default render. Does anybody knows why my code doesn't work? It works fine when not drawing the curves to a PGraphics.
@Henri
Then if you don’t have access to P2D mode, you should check if you really need to create a shape. The conflict is due to the createShape() command. Remember that this methodology will be necessary if you later need to scale up your graphics or to get access to the vertices, (getVertex(), setVertex()), since your intent is to modified the structure of your shape.
Why not test your code in default mode, and draw your shape in a PGraphics instead of a PShape? The code below works fine in every version of Processing, and in JAVA2D mode. Note that it still use a shape (beginShape(), endShape()), but not creating it.