I have a polygon which I am duplicating x number of times according to arbitrary rule. Ideally, I would just like to have an ArrayList with each element being a function pointer to the transform I want to apply. Unfortunately, from what I can tell trying and failing to figure it on my own, java's implementation is not that straight forward. I gather I need to use anonymous classes but I'm not sure how to get it to work.
Here's some pseudo code:
void setup() {
size(400,400);
// define a polygon
PVector[] verts = { new PVector(0,0),new PVector(50,0),new PVector(25,50)};
// I have my transforms as strings, but ideally, they would be function definitions
ArrayList xform = new ArrayList();
xform.add("translate(50,50)");
xform.add("combo(-100,0,PI*.333)");
xform.add("scale(2,1)");
// draw my original triagle
drawIt(verts);
//apply the first transform and draw
xform.get(0); // this would apply the transform
drawIt(verts);
//apply the second transform and draw
xform.get(1);
drawIt(verts);
//apply the third transform and draw
xform.get(2);
drawIt(verts);
}
void drawIt(PVector[] prim) {
beginShape();
vertex(prim[0].x,prim[0].y);
vertex(prim[1].x,prim[1].y);
vertex(prim[2].x,prim[2].y);
endShape(CLOSE);
resetMatrix();
}
void combo(float x, float y, float rot){
translate(x,y);
rotate(rot);
}
Here's some pseudo code:
void setup() {
size(400,400);
// define a polygon
PVector[] verts = { new PVector(0,0),new PVector(50,0),new PVector(25,50)};
// I have my transforms as strings, but ideally, they would be function definitions
ArrayList xform = new ArrayList();
xform.add("translate(50,50)");
xform.add("combo(-100,0,PI*.333)");
xform.add("scale(2,1)");
// draw my original triagle
drawIt(verts);
//apply the first transform and draw
xform.get(0); // this would apply the transform
drawIt(verts);
//apply the second transform and draw
xform.get(1);
drawIt(verts);
//apply the third transform and draw
xform.get(2);
drawIt(verts);
}
void drawIt(PVector[] prim) {
beginShape();
vertex(prim[0].x,prim[0].y);
vertex(prim[1].x,prim[1].y);
vertex(prim[2].x,prim[2].y);
endShape(CLOSE);
resetMatrix();
}
void combo(float x, float y, float rot){
translate(x,y);
rotate(rot);
}
1