How do i make an images sequence run between multiple windows?

Hi guys, i’m having troubles understanding how to make a sequence of images (stored in a class object) run between multiple sketcehs made with the PApplet class. Here’s the code:

int sec = 5;
int fr = 30;
int fn = sec*fr;

File f;
String path;

int num = 2;
SecondApplet[] s = new SecondApplet[num];

int side = 300;

int count = 0;
int cMax = 120;

int randNum = 0;
int oldRN;

Odradek o;

void render() {
  saveFrame("export0/#####.png");

  println("frame num0: " + frameCount + "/" + fn);

  if (frameCount == fn) {
    exit();
  }
}

void settings() {
  size(side, side);
}

void setup() {
  frameRate(fr);
  path ="D:/ACCADEMIA ROMA/Video Editing/esame/multy_sketch";
  init();
  for (int i = 0; i < num; i++) {
    String n = str(i);
    String num = str(i+1);
    f=new File(path + "/export" + num);
    f.mkdir();
    String[] args = {"--location=0,0", "multySketch"};
    s[i] = new SecondApplet(i, randNum);
    PApplet.runSketch(args, s[i]);
  }

  o = new Odradek(side);
}

void draw() {
  background(0);

  count++;

  oldRN = randNum;

  if (count == cMax && randNum == oldRN) init();
  /*
  if (randNum == 0) {
   o.display();
   }
   */
  o.display();
  //render();
}

void init() {
  count = 0;
  randNum = floor(random(num+1));
}

public class SecondApplet extends PApplet {
  int n;
  String num;
  String path;

  int randNum;

  Odradek o;

  SecondApplet(int tn, int trn) {
    n = tn;
    randNum = trn;
  }
  
  public void settings() {
    size(side, side);
    o = new Odradek(side);
  }

  public void setup() {
    frameRate(fr);
    num = str(n+1);
    path ="D:/ACCADEMIA ROMA/Video Editing/esame/multy_sketch/export" + num;
  }

  public void draw() {
    background(0);

    println("Applet " + num + ": " + randNum);

    /*
    if (randNum == n+1) {
     o.display();
     }
     */
    o.display();
    //println("frame num" + num + ": " + frameCount + "/" + fn);

    //saveFrame(path +"/" + "_#####.png");
  }
}

and here’s the class for the images sequence:

class Odradek {
  int num = 21;

  PImage[] foto0 = new PImage[num];
  PImage[] foto1 = new PImage[num];
  PImage mix;

  float t;

  int side;

  Odradek(int ts) {
    side = ts;
    for (int i = 0; i < num; i++) {
      String n;

      if (i > 9) {
        n = str(i);
      } else {
        n = "0" + str(i);
      }

      foto0[i] = requestImage(n + ".JPG");
      foto0[i] = loadImage(n + ".JPG");

      foto1[i] = requestImage(n + ".JPG");
      foto1[i] = loadImage(n + ".JPG");
    }

    mix = createImage(side, side, RGB);
  }

  void display() {
    t = t + 0.6;
    float threshold = noise(t);
    threshold = map(threshold, 0, 1, 10, 250);

    int r0 = floor(random(num));
    int r1 = floor(random(num));

    foto0[r0].loadPixels();
    foto1[r1].loadPixels();
    foto0[r0].resize(side, side);
    foto1[r1].resize(side, side);

    mix.loadPixels();

    for (int x = 0; x < side; x+=(int(random(1, 3)))) {
      for (int y = 0; y < side; y++) {
        int loc = x + y * side;
        float red0 = red(foto0[r0].pixels[loc]);
        float green0 = green(foto0[r0].pixels[loc]);
        float blue0 = blue(foto0[r0].pixels[loc]);

        float red1 = red(foto1[r1].pixels[loc]);
        float green1 = green(foto1[r1].pixels[loc]);
        float blue1 = blue(foto1[r1].pixels[loc]);

        if (brightness(foto0[r0].pixels[loc]) < threshold) {
          mix.pixels[loc] = color(red1, green1, blue1);
        } else if (brightness(foto1[r1].pixels[loc]) > threshold) {
          mix.pixels[loc] = color(red0, green0, blue0);
        }
      }
    }

    mix.updatePixels();
    image(mix, 0, 0, side, side);
  }
}

I don’t understand what i’m doing wrong cause this is the first time I’m using the PApplet class. Another thing I would like to do is to make this sequence “jump” between the windows. I thought that using a variable (randNum) that changes its own value over time to trigger the display method of the odradek class in every sketches may have worked but it didn’t. Can somebody help me?