Loading...
Logo
Processing Forum
Hello,
 I would like to run a sketch with some buttons and then on the click of a button another sketch should start running in the same display with a close button to go back to previous sketch .

I am not getting how to implement this.
Please help!!

Replies(3)

If you have access to the source code for both sketches, you could just merge them in the code directly, and decide which one is running by keeping track of some state variable, like so:

Copy code
  1. int state;

    void setup(){
      size(300,300);
      state = 0;
    }

    void draw(){
     
      if(state==0){
        background(0);
        state = 1;
      }
     
      if(state == 1){
        stroke(128 + random(128), 128 + random(128), 128 + random(128));
        noFill();
        line( random(width), random(height), random(width), random(height) );
      }
     
      if(state==2){
        fill(128 + random(128), 128 + random(128), 128 + random(128));
        noStroke();
        ellipseMode(CENTER);
        ellipse(random(width), random(height), 20, 20);
      }
     
    }

    void mouseClicked(){
      if(state==0){ return; }
      if(state==1){ state=2; return; }
      if(state==2){ state=1; return; }
    }

    void keyPressed(){
      if(state==0){ return; }
      if(state==1){ state=0; return; }
      if(state==2){ background(255,0,0); return; }
    }
You can check out the napplet library:

Mother can also mix sketches but it's designed with VJing in mind, which may or may not be what you're going for:

=)

Thanks tfguy44 and jack for your reply.

I believe NApplet is  what I am looking for.But I also want to control the creation and deletion of the NApplet .
That is I have certain buttons on the base sketch and on click of any of the button previous NApplet should be destroyed and new sketch should open up.
I know how to create NApplet but doesn't have any idea about how to kill them.

Please help.