# Need help merging several sketches

**URL:** <https://discourse.processing.org/t/need-help-merging-several-sketches/25083>\
**Category:** Libraries\
**Tags:** homework\
**Created:** [October 31, 2020, 9:34pm UTC](https://discourse.processing.org/t/need-help-merging-several-sketches/25083 "2020-10-31T21:34:03Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![qelouisa](https://avatars.discourse-cdn.com/v4/letter/q/898d66/32.png) [@qelouisa](https://discourse.processing.org/u/qelouisa)\
**Post date:** [October 31, 2020, 9:34pm UTC](https://discourse.processing.org/t/need-help-merging-several-sketches/25083/1 "2020-10-31T21:34:03Z")

</div>

Hello everyone, for a school project I am working on interactive visuals with the kinect. I have 3 processing sketches which I want to merge into one, so the visuals loop over into each other. However I am at a loss on how to do this. I have tried turning them into functions and play them in draw() but then nothing happens when playing the sketch. Im a beginner and all these sketches and the average point tracking were made using tutorials.

What I want to make is that the visuals loop over into another one after 20 seconds or so. Any help would be appreciated.

Since it is quite a lot of code I have uploaded my PDE files here:

> **[qelouisa/Processing-Sketches](https://github.com/qelouisa/Processing-Sketches)**
>
> Contribute to qelouisa/Processing-Sketches development by creating an account on GitHub.

The files uploaded with kinect in the filename have the kinect + point tracking code in them, the last 3 work on mouse tracking.

Thanks in advance 🎉

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [November 1, 2020, 6:29pm UTC](https://discourse.processing.org/t/need-help-merging-several-sketches/25083/2 "2020-11-01T18:29:51Z")

</div>

I think that’s similar but he has problems:

See [Load a different background sketch and automatically change each 30 seconds](https://discourse.processing.org/t/load-a-different-background-sketch-and-automatically-change-each-30-seconds/25101/5)

In general from draw() call new functions draw1, draw2 and draw3 depending on sketchNumber, a new variable you have to declare globally.

In draw1 / draw2/ draw3 copy your draw function from the old sketches

Increase sketchNumber when `frameCount%10*frameRate==0`

---

<div class="post-metadata">

**Author:** ![qelouisa](https://avatars.discourse-cdn.com/v4/letter/q/898d66/32.png) [@qelouisa](https://discourse.processing.org/u/qelouisa)\
**Post date:** [November 1, 2020, 7:24pm UTC](https://discourse.processing.org/t/need-help-merging-several-sketches/25083/3 "2020-11-01T19:24:10Z")

</div>

Hi, thanks for your reply! I managed to get it work yesterday evening luckily. It now changes on the amount of frames gone by, but changing it to seconds will probably work a bit better. Thanks for the reply to the right thread!

If anyone finds this thread in the future, this is the code I used;

```auto
void draw () {
  if (frameCount < 10 * frameRate) {
    drawSquare();
  } else if (frameCount < 20 * frameRate) {
    drawCircle();
  } else if (frameCount < 30 * frameRate) {
    drawEllipse();
  }
}

```

make sure all your code in the void functioncalls is working. change the numbers depending on how long you want them to last.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [November 1, 2020, 8:46pm UTC](https://discourse.processing.org/t/need-help-merging-several-sketches/25083/4 "2020-11-01T20:46:18Z")

</div>

Yeah, we could also make a timer using millis() etc.

Not sure whether your code works more than one cycle?

---

<div class="post-metadata">

**Author:** ![qelouisa](https://avatars.discourse-cdn.com/v4/letter/q/898d66/32.png) [@qelouisa](https://discourse.processing.org/u/qelouisa)\
**Post date:** [November 1, 2020, 8:54pm UTC](https://discourse.processing.org/t/need-help-merging-several-sketches/25083/5 "2020-11-01T20:54:28Z")

</div>

It doesn’t, but I am not too worried about that. Would it work in more than one cycle with millis()?

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [November 1, 2020, 9:12pm UTC](https://discourse.processing.org/t/need-help-merging-several-sketches/25083/6 "2020-11-01T21:12:19Z")

</div>

Yes.

OR when you use my advice above

with

switch(sketchNumber) {  
case 0:  
draw1();  
break;

case 1:  
…

}

---

<div class="post-metadata">

**Author:** ![qelouisa](https://avatars.discourse-cdn.com/v4/letter/q/898d66/32.png) [@qelouisa](https://discourse.processing.org/u/qelouisa)\
**Post date:** [November 1, 2020, 9:18pm UTC](https://discourse.processing.org/t/need-help-merging-several-sketches/25083/7 "2020-11-01T21:18:08Z")

</div>

Ah thats great! Ill try that out then as well. Thank you 🙂
