How do you apply PGraphics masks to multiple images?

I am trying to do the following:

Pulling from a data set of multiple images (let's say 6 images in this case, though it will be thousands in the final piece), draw a randomly placed masked ellipse from image 1, then draw a randomly placed masked ellipse from image 2, and so on. The below code appears to be close but I can't figure out what I'm doing wrong.

This is the code I'm trying to augment (which works well with just one image):

PImage img;
PGraphics mask;

void setup(){
  size (1000, 1000);
  img = loadImage("<a href="http://foglobe.com/data_images/main/frank-zappa/frank-zappa-06.jpg" target="_blank" rel="nofollow">http://foglobe.com/data_images/main/frank-zappa/frank-zappa-06.jpg</a>;");
  mask = createGraphics(width, height);
  background(40);
}

void draw(){

  mask.beginDraw();
  mask.noStroke();
  mask.fill(255);
  mask.ellipse(random(width), random(height), 20, 20);
  mask.endDraw();

  img.mask(mask);
  image(img, 0 ,0);
}

This is the code I'm trying to make work with 6 images, and is close but is not quite working:

PGraphics mask;
int countB = 0; 
int numImagesA = 6;
PImage[] imgA = new PImage[numImagesA];

void setup(){
  size (640, 360);
  mask = createGraphics(width, height);
  background(40);
}

void draw(){
  PImage imgA = loadImage("CarlSagan" + (countB) + ".jpg"); 

  mask.beginDraw();
  mask.noStroke();
  mask.fill(255);
  mask.ellipse(random(width), random(height), 50, 50);
  mask.endDraw();

  imgA.mask(mask);
  image(imgA, 0 ,0);

  countB++;
  if (countB == numImagesA) {
     countB = 0;  
   }

  println (countB);
}
Tagged:

Answers

This discussion has been closed.