Painting/revealing a layer

Hi @bringmeflowers,

better use the mask function for this … check out…

PGraphics maskimg;
PImage underlyingimg;

void setup() {
  size(800,800,P2D);
  underlyingimg = loadImage("image.jpg");

  // create mask (should be same as the underlying image size)
  maskimg = createGraphics(underlyingimg.width,underlyingimg.height,P2D);

  // initialize the whole mask with black (everything hidden)
  maskimg.beginDraw();
  maskimg.background(0);
  maskimg.noStroke();
  maskimg.fill(255);
  maskimg.endDraw();
}

void draw() {
  background(0);

  if (mousePressed) {
    // if mousePressed draw the area with white pixels (revealed)
    // just for example using a circle brush (ie ellipse) 
    maskimg.beginDraw();
    maskimg.ellipse(mouseX,mouseY,50,50);
    maskimg.endDraw();     
  }  
  // apply the mask to the underlying image and paint it
  underlyingimg.mask(maskimg);
  image(underlyingimg, 0, 0);
}

Cheers
— mnse

2 Likes