How do I slowly layer photos to appear on top of eachother?

This example loads all images inside subfolder “data/” and assign them to a PImage[] array: :framed_picture:

/**
 * Load All Images (v1.0.0)
 * GoToLoop (2022/May/04)
 *
 * https://Discourse.Processing.org/t/
 * how-do-i-slowly-layer-photos-to-appear-on-top-of-eachother/36698/5
 */

static final String PICS_EXTS = "extensions=,png,jpg,jpeg,gif,tif,tiff,tga,bmp";

static final float FPS = .25;

PImage[] images;

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

  frameRate(FPS);
  imageMode(CENTER);

  images = loadAllImages();
  if (images.length == 0)  exit();
}

void draw() {
  clear();
  image(images[frameCount % images.length], width >> 1, height >> 1);
}

PImage[] loadAllImages() {
  final File dir = dataFile("");
  println(dir);

  String[] imagePaths = {};
  int imagesFound = 0;

  if (dir.isDirectory()) {
    imagePaths = listPaths(dir.getPath(), "files", "recursive", PICS_EXTS);
    imagesFound = imagePaths.length;
    java.util.Arrays.sort(imagePaths);
  }

  printArray(imagePaths);
  println("Found", imagesFound, "image(s)");

  final PImage[] imgs = new PImage[imagesFound];
  for (int i = 0; i < imagesFound; imgs[i] = loadImage(imagePaths[i++]));

  return imgs;
}
1 Like