We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
Shapes. PShape (Read 1040 times)
Shapes. PShape
Mar 1st, 2010, 12:41am
 
This might be a dumb question, but I couldn't find the answer in the reference.
Are PShape objects and the shapes created within beginShape() endShape() the same type of objects? Or, in other words, how can I create/draw a PShape object other than loading a *.svg file?

I would like to create my custom shape using vertices etc. within the beginShape() - endShape() section, but would then like to make use of the nice PShape() functions like rotate(), scale() etc.
Is it possible, or not?
If yes, could somebody please give a short example? (Such an example would then be needed in the reference as well...)
Re: Shapes. PShape
Reply #1 - Mar 1st, 2010, 12:49am
 
sure, there is nothing special about it. when creating your custom shape using begin and endShape, you can do any transformation using, scale, rotate, translate...


void setup() {
 size(200,200);
 smooth();
 background(255);

}

void draw() {
 background(255);
translate(width/2,height/2);
rotate(radians(frameCount/2.0));
scale(sin(frameCount/30.0));
beginShape();
vertex(20, 20);
vertex(40, 20);
vertex(40, 40);
vertex(60, 40);
vertex(60, 60);
vertex(20, 60);
endShape(CLOSE);

}
Re: Shapes. PShape
Reply #2 - Mar 1st, 2010, 12:54am
 
ah got it. you want to rotate the single vertices themself ?
Re: Shapes. PShape
Reply #3 - Mar 1st, 2010, 12:57am
 
you can maybe use http://processing.org/reference/modelX_.html
to translate some single vertices in a pshape. could work but doesnt look really handy
Re: Shapes. PShape
Reply #4 - Mar 1st, 2010, 1:36am
 
See PShape:
"In-progress class to handle shape data, currently to be considered of alpha or beta quality. [...] changes may include: addition of proper accessors to read shape vertex and coloring data [...] a means of creating PShape objects ala beginShape() and endShape()."
So it doesn't seem to be there yet.
You can create your own class extending PShape or even just functions doing the right combination of begin/endShape() and stuff inside.
Re: Shapes. PShape
Reply #5 - Mar 1st, 2010, 9:06am
 
Thanks both of you. My main question was, if PShape and "beginShape/endShape" are basically two version of the same thing or something different. They are different, as I could have found out by reading more carefully  Wink

I think the way to go is then to create my own class which uses the beginShape/endShape drawing routine for containing "my" shapes and forget about PShape for now...
Re: Shapes. PShape
Reply #6 - Mar 1st, 2010, 9:21am
 
As PhiLho says, you can try extending the PShape class. I guess you'll have to override the draw() method :

Code:
class MyObject extends PShape {

void draw(PGraphics g) {
g.beginShape();
g.vertex(...);
...
g.endShape();
}

}
Page Index Toggle Pages: 1