With this code I get on the edge black ring and all black pixels inside the circle are coverted to transparent..
Help me improve this code..
- PGraphics pgTexture, pgMask, pgShape, savearea;
color pix;
int i;
void setup()
{
size(800, 500);
PImage img = loadImage("800x500.jpg");
pgMask = createGraphics(width, height, JAVA2D);
pgShape = createGraphics(width, height, P2D);
savearea = createGraphics(100, 100, JAVA2D);
pgTexture = createGraphics(width, height, JAVA2D);
pgTexture.beginDraw();
pgTexture.image(img, 0, 0);
pgTexture.endDraw();
}
void draw()
{
background(0);
DrawTextured();
}
void DrawTextured()
{
pgMask.background(0);
pgMask.fill(255);
pgMask.noStroke();
DrawCircle(pgMask);
PImage piMask = pgMask.get(0, 0, width, height);
pgShape.image(pgTexture, 0, 0);
pgShape.mask(piMask);
image(pgShape, 0, 0);
println(frameRate);
}
void DrawCircle(PGraphics g)
{
g.beginDraw();
g.smooth();
g.noStroke();
g.ellipse(mouseX, mouseY, 100, 100);
g.endDraw();
}
void mousePressed() {
savearea.set(0, 0, get(mouseX-50, mouseY-50, 100, 100));
savearea.loadPixels();
for (int x=0; x < 100; x++) {
for (int y=0; y < 100; y++) {
i = ((y * 100) + x);
pix = savearea.pixels[i];
if(pix == color(0, 0, 0)) savearea.pixels[i] = color(0, 0, 0, 0);
}
}
savearea.updatePixels();
savearea.save("data/circleHole.png");
}
1