# 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:** 3

<div class="post-metadata">

### Author: ![Gus\_Fermin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gus_fermin/32/5851_2.png) [@Gus\_Fermin](https://discourse.processing.org/u/Gus_Fermin)
#### Post date: [August 14, 2020, 4:46pm UTC](https://discourse.processing.org/t/animation-with-3-different-sketches-combined-using-switch-with-keyboard-input/23258/3 "2020-08-14T16:46:49Z")

</div>

Thank you very much for your reply, I have a much more simple code that I mentioned in the post that I adapted, it is this one, and it works, very similar to yours, but when I implemented in mine, the relevant parts they are the same `(switch, case numbers, etc..)` but for some reason it does not work in mine, here is the example code very similar to yours that I did before I implemented the `switch` states with keyboard input:

```auto
int sketchToDraw;

void setup() {
  size(500, 500);
  noStroke();
  smooth();
}

void draw() {

  switch(sketchToDraw) {
  case 0: drawScreenOne(); break;
  case 1: drawScreenTwo(); break;
  case 2: drawScreenThree(); break;
  default: background(0); break;
  }
}

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

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

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

  if (key == '4')
    println("left");
}

/// the functions found in tabs that I call from the main `draw()`
void drawScreenOne() {
  background(255, 0, 0);
  fill(255);
  ellipse(100, 100, 400, 400);
}

void drawScreenTwo() {
  background(0, 255, 0);
  fill(0);
  rect(250, 40, 250, 400);
}
void drawScreenThree() {
  background(0, 0, 255);
  fill(255, 255, 0);
  triangle(150, 100, 150, 400, 450, 250);
}

```

---

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