Interactive shape masking with PGraphics

Hi there!

Building up on a great post from the old forum: https://forum.processing.org/two/discussion/comment/77997/#Comment_77997

shape. masking with PGraphics — was wondering if some one can give me a tip to how to add mouseX and mouseY to the masked shape? Was trying the following, but it seems that needs a bit more work.

PImage img;  // Declare variable "a" of type PImage
PGraphics maskImage;

void setup()  {
  
  size(800,600);

  img = loadImage("MyImage_1.jpg");
  // Create mask
  maskImage = createGraphics(width,height);
  maskImage.beginDraw();
  maskImage.rect(mouseX,mouseY, 300, 200);
  maskImage.endDraw();
  img.mask(maskImage);
}

Many thanks in advance!

Found an easy solution to obtain what I wanted:

PImage img;  // Declare variable "a" of type PImage
PGraphics maskImage;

void setup()  {
  
  size(800,600);

  img = loadImage("MyImage_1.jpg");
  
}


void draw()  {
  
  // Create mask
  maskImage = createGraphics(width,height);
  maskImage.beginDraw();
  maskImage.rect(mouseX,mouseY, 300, 200);
  noStroke();
  maskImage.endDraw();
  img.mask(maskImage);
  fill(0);
  rect(0,0, width, height);
  image(img,0,0);
  
  
}


1 Like