How can I use the mouseClick() function to load a new image from an array?

edited December 2017 in Questions about Code

Hello, everyone. I'm onto the second part of my project where I need to cycle through the images in my array one by one with each mouse click.

Here are the relevant instructions:

mouseClicked will do the following (feel free to change details to suit your preference, provided your solution works):

Create a new image, called newimg. Use createImage for that

Call loadPixels on the new image and the original image. This prepares the .pixels array for use.

Here is what I have so far:

PImage [] retinalImages = new PImage[10];

void setup() {
  size(800, 800);
  for (int i = 0; i < retinalImages.length; i++) {
    retinalImages[i] = loadImage("retinal" + i + ".png");
  }
}

void draw() {
 background(255);
 image(retinalImages[0], 0, 0);
}

void mouseClicked() {
  if(LEFT == mouseButton) {
   PImage retinalImages = createImage(800, 800, RGB);
   retinalImages.loadPixels();

  }
  updatePixels();
}

I tried creating another for loop in the mouseClicked() function, but that didn't work. I think I need to somehow tell the mouseClicked() function where to pull this new image from (my array), but I'm not sure how to do that. If someone could help point me in the right direction I would really appreciate it. Thank you.

Tagged:

Answers

Sign In or Register to comment.