Calling processing sketches within a processing sketch

My processing code is getting very long. I’m essentially building a slideshow. Is it possible to build each slide individually and then call each one in the main program?
This is the kind of thing I did when writing my dissertation in LaTeX. I wrote each chapter individually, and then called each one in the main program. So that’s the kind of solution I am hoping for.

You can create two seperate sketches that communicate with each other via server.

Server

 import processing.net.*;

Server s;
Client c;
int data_alt[]={9, 9};
String input;
int data[];
int z=1;
int feld[][]={{0, 0, 0}, {0, 0, 0}, {0, 0, 0}};
int sending=0;

void setup() 
{
  size(600, 600);
  // background(204);
  fill(0);
  stroke(0);
  frameRate(20); // Slow it down a little
  s = new Server(this, 12360); // Start a simple server on a port
}

void draw() 
{    
  //send
  s.write("insert_variables_here"+"\n");

  //recieve
  c = s.available();
  if (c != null) {
    input = c.readString();
    input = input.substring(0, input.indexOf("\n")); // Only up to the newline
    println(input);
    data = int(split(input, ' ')); // Split values into an array
  }
}

Client

import processing.net.*;

Client c;
String input;
int[] data;
void setup() 
{
  c = new Client(this, ".....", 12360); // Replace with your server's IP and port
}

void draw() 
{
}
void gain() {
  c.write("Insert_variable_here");
  if (c.available() > 0) {
    input = c.readString();
    input = input.substring(0, input.indexOf("\n")); // Only up to the newline
    data = int(split(input, ' ')); // Split values into an array
  }
}

Thank you, this looks like just what I need. I’m not super familiar with terms like server, IP, and port, but I think this will help me understand once I dig into it.
Thank you very much for your help.

1 Like