Animation with 3 different sketches combined using Switch with keyboard input

Hello,

I started an exploration of this with some basic code (your code stripped down ) NOT including the sound libraries.

Click Here for Code
int sketchToDraw; 

void setup() 
  {
  size(300, 300, P3D);
  textAlign(CENTER);
  textSize(48);
  }

void draw() 
  {
  background(0);
  
  switch (sketchToDraw) 
    {
  case 0:  
    draw1(); break;
  case 1:  
    draw2(); break;
  case 2:  
    draw3(); break;
  default: 
    background(0); break;
  }
}

void keyPressed() 
  {
  if (key == '1')
    sketchToDraw = 0;

  if (key == '2')
    sketchToDraw = 1;

  if (key == '3')
    sketchToDraw = 2;
  }

void draw1() 
  {
  text("Draw 1", width/2, height/2);
  println("draw 1");
  }

void draw2() 
  {
  text("Draw 2", width/2, height/2); 
  println("draw 2");
  }

void draw3() 
  {    
  text("Draw 3", width/2, height/2);    
  println("draw 3");
  }

This worked as is and with your 3 draw functions which I did not include here.
I removed all the sound code for testing.

Printing to console is a great tool in code development:

Be sure to comment these when not using! They can slow things down.

There are many ways to do this.
An example here of this:
https://discourse.processing.org/t/animation-that-transitions-using-framecount/15378
Start simple and build on that.

:)

1 Like