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.
IndexProgramming Questions & HelpSyntax Questions › render java geometry
Page Index Toggle Pages: 1
render java geometry (Read 915 times)
render java geometry
Jul 24th, 2007, 4:13pm
 
Hi there,

Is there a way to render Java geometry classes?
In Java you have to write smt like:

g2.draw(new Rectangle2D.Double(x, y,rectwidth,rectheight));

Is there a similar way in processing to render Java primitives and shapes geometries with generalPath?

Thanks Smiley

Re: render java geometry
Reply #1 - Jul 25th, 2007, 10:26am
 
there are a few calls you can use to draw basic geometry/shapes.

rect( x, y, size, size )
ellipse( ... )
sphere (... )
box( ... )
Re: render java geometry
Reply #2 - Jul 26th, 2007, 10:55pm
 
yes I know these.. the problem is that I have geometries created with the java.awt.geom.GeneralPath and the java.awt.Polygon classes. I was wandering if there is a way to render these geometries.

But thanks a lot anyways..
Re: render java geometry
Reply #3 - Jul 26th, 2007, 11:29pm
 
The only way to render them is to step through them yourself and convert their meaning to processing meaning. There is no automatic way to draw them.

e.g. if it's a Rectangle2D, get the position/size out, and pass that to rect(...);
Re: render java geometry
Reply #4 - Jul 27th, 2007, 12:10am
 
you can use a PathIterator and map the calls to beginShape() and endShape(). i think there's an example elsewhere on the board that shows how to do this with font glyph shapes.
Re: render java geometry
Reply #5 - Jul 29th, 2007, 4:16am
 
thanks a lot! Smiley

btw, I came up with that solution based on the pathIterrator:


Code:

class myPolygon{
java.awt.geom.GeneralPath trace = new GeneralPath();

myPolygon(float[] x,float[] y){ //constructor from points
trace.moveTo(x[0],y[0]);
for (int i=1; i< x.length;i++){
trace.lineTo(x[i],y[i]);
}
trace.closePath();
}


void draw(){
PathIterator pi = trace.getPathIterator(null);
float[] pts = new float[2];
while (!pi.isDone()) {
int type = pi.currentSegment(pts);
if (type == PathIterator.SEG_MOVETO){
beginShape();
vertex(pts[0],pts[1]);
}
if (type == PathIterator.SEG_LINETO) { // LINETO
vertex(pts[0],pts[1]);
//println(pts[0]+","+pts[1]);
}
if (type == PathIterator.SEG_CLOSE) {
endShape();
}
pi.next();
}
}
}


that will do. Smiley I hope it's not terrible.
Page Index Toggle Pages: 1