alphachapmtl
Full Member
Offline
Posts: 128
Canada
Re: Shape() with hole
Reply #3 - Aug 19th , 2007, 12:08pm
The following message from <JohnG> gives a solution: One possible way is to pick a vertex on the outer poly, and then find the closest vertex on the inner, and use that as an invisible break.. so you just draw one poly, like so: Draw from "outside break" vertex around the outside back to itself, but instead of ending there, then draw the inside one, and go around that, in the opposite direction, back to the inside break, and then the last vertex is the outside break again. This test program shows an example: //polygonhole1 //2007-aug-17 //alphachapmtl int x0,y0; void setup() { size(900,400); background(0); // square_cyclic x0=width/6; y0=height/2; for (int i=0;i<8;i++) { int delta=20*i; stroke(0,0,200,50); fill(200,0,0,50); beginShape();//cyclic order vertex(x0-delta, y0-delta); vertex(x0-delta, y0+delta); vertex(x0+delta, y0+delta); vertex(x0+delta, y0-delta); endShape(CLOSE); }//for // square_cyclic + insquare_cyclic x0=3*width/6; y0=height/2; for (int i=0;i<8;i++) { int delta=20*i; stroke(0,0,200,50); fill(200,0,0,50); beginShape();//cyclic order vertex(x0-delta, y0-delta); vertex(x0-delta, y0+delta); vertex(x0+delta, y0+delta); vertex(x0+delta, y0-delta); vertex(x0-delta, y0-delta); if (i>0) {//cyclic order int deltaOld=delta-20; vertex(x0-deltaOld, y0-deltaOld); vertex(x0-deltaOld, y0+deltaOld); vertex(x0+deltaOld, y0+deltaOld); vertex(x0+deltaOld, y0-deltaOld); vertex(x0-deltaOld, y0-deltaOld); vertex(x0-delta, y0-delta); } endShape(); }//for // square_cyclic + insquare_anticyclic >> THIS WORKS !! x0=5*width/6; y0=height/2; for (int i=0;i<8;i++) { int delta=20*i; stroke(0,0,200,50); fill(200,0,0,50); beginShape();//cyclic order vertex(x0-delta, y0-delta); vertex(x0-delta, y0+delta); vertex(x0+delta, y0+delta); vertex(x0+delta, y0-delta); vertex(x0-delta, y0-delta); if (i>0) {//anticyclic order int deltaOld=delta-20; vertex(x0-deltaOld, y0-deltaOld); vertex(x0+deltaOld, y0-deltaOld); vertex(x0+deltaOld, y0+deltaOld); vertex(x0-deltaOld, y0+deltaOld); vertex(x0-deltaOld, y0-deltaOld); vertex(x0-delta, y0-delta); } endShape(); }//for exit(); } void draw() { }