# Animation with 3 different sketches combined using Switch with keyboard input

**URL:** <https://discourse.processing.org/t/animation-with-3-different-sketches-combined-using-switch-with-keyboard-input/23258>\
**Category:** Libraries\
**Created:** [August 14, 2020, 4:20pm UTC](https://discourse.processing.org/t/animation-with-3-different-sketches-combined-using-switch-with-keyboard-input/23258 "2020-08-14T16:20:32Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [August 14, 2020, 4:41pm UTC](https://discourse.processing.org/t/animation-with-3-different-sketches-combined-using-switch-with-keyboard-input/23258/2 "2020-08-14T16:41:10Z")

</div>

Hello,

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

> **Click Here for Code**
>
> ```auto
> 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:

> **[println() / Reference](https://processing.org/reference/println_.html)**
>
> The println() function writes to the console area, the black rectangle at the bottom of the Processing environment. This function is often helpful for looking at the data a program is producing…

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

> [@Gus\_Fermin](#):
>
> Eventually I will try and implement timed events using a timer or `frameCount`

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

`:)`

---

_[View the full topic](https://discourse.processing.org/t/animation-with-3-different-sketches-combined-using-switch-with-keyboard-input/23258)._
