# Multiple parallel animations

**URL:** https://discourse.processing.org/t/multiple-parallel-animations/780
**Category:** Processing
**Created:** [June 7, 2018, 7:22pm UTC](https://discourse.processing.org/t/multiple-parallel-animations/780 "2018-06-07T19:22:55Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Aravindh](https://avatars.discourse-cdn.com/v4/letter/a/f0a364/32.png) [@Aravindh](https://discourse.processing.org/u/Aravindh)
#### Post date: [June 7, 2018, 7:22pm UTC](https://discourse.processing.org/t/multiple-parallel-animations/780/1 "2018-06-07T19:22:55Z")

</div>

Hello, I wanted to ask if it is possible to have multiple parallel animations at the same time in processing. Something like[https://youtu.be/spUNpyF58BY?t=271](https://youtu.be/spUNpyF58BY?t=271). Basically I want two sections displayed at the same time, each having its own shape and its own animation and also the background color should change separately. The reason i am asking this is that I see the api as backgroundColor which sets the color of the entire screen. not that of a specific shape. Kindly help me understand if this is possible

---

<div class="post-metadata">

### Author: ![Trilobyte](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/trilobyte/32/361_2.png) [@Trilobyte](https://discourse.processing.org/u/Trilobyte)
#### Post date: [June 7, 2018, 8:04pm UTC](https://discourse.processing.org/t/multiple-parallel-animations/780/2 "2018-06-07T20:04:10Z")

</div>

@Aravindh,  
If I’m understanding you correctly, you want to run two “animations” at the same time on a single window. This is possible, and you can keep track of relative positions using pushMatrix() and popMatrix(). I would also use translate().  
[https://processing.org/reference/pushMatrix\_.html](https://processing.org/reference/pushMatrix_.html)  
To make two different backgrounds, I would recommend using rect() to draw a new rectangular background. Use fill() to color it. You can customize this background to be whatever shape or color you want. Hope this helps. Good luck!  
-Trilobyte

---

<div class="post-metadata">

### Author: ![WakeMeAtThree](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/wakemeatthree/32/38_2.png) [@WakeMeAtThree](https://discourse.processing.org/u/WakeMeAtThree)
#### Post date: [June 7, 2018, 11:14pm UTC](https://discourse.processing.org/t/multiple-parallel-animations/780/3 "2018-06-07T23:14:00Z")

</div>

> [@Aravindh](#):
>
> wo sections displayed at the same time, each having its own shape and its own animation and also the background color should change separately. The reason i am asking this is that I see the api as backgroundColor which sets the color of the entire screen. not that of a specific shape. Kindly help me understand if this is possible

You can use `PGraphics` to do that. Check out the documentation [reference for it here](https://processing.org/reference/PGraphics.html). You can essentially use it to create two canvases and then call them in your sketch. Here’s a simple commented example I wrote to demonstrate how you can use it. It’s two different views of a rotating box.

![output](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/1X/296f0b5aeced4ccf7da5e6a09b9169eff19c4433.gif)

```java
PGraphics top, persp;
float a;

void setup() {
  size(400, 200, P3D);
  top = createGraphics(200, 200, P3D);
  persp = createGraphics(200, 200, P3D);
}

void draw() {
  clear();
  //Run scenes
  drawScene(top, 0, a);
  drawScene(persp, PI/4, a);
  
  //Display scenes
  image(top, 0, 0);
  image(persp, 200, 0);
  
  //Animate
  a+=0.1;
}

void drawScene(PGraphics scene, float angle, float time) {
  scene.beginDraw();
  scene.clear();
  
  //Outline frame
  scene.pushStyle();
  scene.noFill();
  scene.stroke(255);
  scene.rect(0, 0, scene.width, scene.height);
  scene.popStyle();

  //Move coordinate system
  scene.translate(scene.width/2, scene.height/2);
  scene.rotateX(angle);
  scene.rotateZ(time);
  
  //Generate box
  scene.box(50);
  
  //Draw reference point
  scene.pushStyle();
  scene.stroke(255, 0, 0);
  scene.strokeWeight(15);
  scene.point(25, 25, 25);
  scene.popStyle();
  
  scene.endDraw();
}

```
