breakShape() with pattern shape
in
Programming Questions
•
2 years ago
Hi,
I´m using breakShape to draw a rectangle that has a circular hole in the middle, and It works just fine!
My problem is when I want that rectangle to have a pattern instead of a fill(color).
If somebody could help me with this... maybe there is a work around I´m not seeing...
My goal is to save an image.png that has a square pattern with a transparente hole in the middle.
The code that I´m putting here put me in a dead end, because breakShape only works with JAVA2D, and textures don´t work with JAVA2D.
Need help....
int r = 65;
int a = 15;
PGraphics pg, pg2;
void setup() {
size(200, 200, P2D);
pg = createGraphics(width, height, P2D);
pg2 = createGraphics(width, height, JAVA2D);
}
void draw() {
pg.beginDraw();
pg.smooth();
pg.noStroke();
for (int i=0; i<=width; i+=6) {
pg.beginShape();
pg.fill(175, 0, 0);
pg.vertex(i, 0);
pg.vertex(i+1, 0);
pg.vertex(i+1, height);
pg.vertex(i, height);
pg.vertex(i, 0);
pg.endShape(CLOSE);
pg.beginShape();
pg.fill(255, 0, 0);
pg.vertex(i+1, 0);
pg.vertex(i+6, 0);
pg.vertex(i+6, height);
pg.vertex(i+1, height);
pg.vertex(i+1, 0);
pg.endShape(CLOSE);
}
pg.endDraw();
pg2.beginDraw();
pg2.smooth();
pg2.noStroke();
pg2.noFill();
pg2.textureMode(NORMALIZED);
pg2.beginShape();
pg2.texture(pg);
pg2.vertex(0, 0, 0, 0);
pg2.vertex(width, 0, 1, 0);
pg2.vertex(width, height, 1, 1);
pg2.vertex(0, height, 0, 1);
pg2.vertex(0, 0, 0, 0);
pg2.breakShape();
pg2.vertex(width/2, r);
pg2.bezierVertex(r+a, r, r, r+a, r, height/2);
pg2.bezierVertex(r, (height-r)-a, r+a, (height-r), width/2, height-r);
pg2.bezierVertex((width-r)-a, (height-r), (width-r), (height-r)-a, width-r, height/2);
pg2.bezierVertex((width-r), r+a, (width-r)-a, r, width/2, r);
pg2.vertex(width/2, r);
pg2.endShape(CLOSE);
pg2.endDraw();
image(pg2, 0, 0, width, height);
}
void mousePressed() {
pg2.save("data/circleHole.png");
}
Thanks!
1