Hi~I tried to draw custom shapes(hexagon) on a transparent P2D PGraphics for later I would change the background color. I don’t want any strokes, but there are unexpected outlines of the shapes shown on the P2D PGraphic.
The buttom left hexagon is the shape which follows the mouse, others are drawn on the P2D PGraphics that slightly have outlines.
If I use normal PGraphics, there will be no strokes and that’s what I want. But I have to use P2D for some further reasons. I hope that someone can help me figuring out the problem. Here are the codes:
PShape hexagon;
PGraphics pg;
void setup(){
size(400,400,P2D);
smooth(8);
hexagon = createShape();
hexagon.setFill(color(239, 237, 220));
hexagon.setStroke(false);
hexagon.beginShape();
for (int i = 0; i < 6; i++) {
float angle = i * PI/3 + PI/6;
hexagon.vertex(cos(angle) * 50, sin(angle)*50);
}
hexagon.endShape(CLOSE);
pg = createGraphics(width,height,P2D);
pg.smooth(8);
pg.beginDraw();
pg.noStroke();
pg.endDraw();
}
void draw(){
background(255);
image(pg,0,0);
shape(hexagon,mouseX,mouseY);
}
void mouseClicked(){
pg.beginDraw();
pg.shape(hexagon,mouseX,mouseY);
pg.endDraw();
}