# Two windows with 'one draw()'

**URL:** <https://discourse.processing.org/t/two-windows-with-one-draw/11388>\
**Category:** Processing.py\
**Created:** [May 19, 2019, 4:30pm UTC](https://discourse.processing.org/t/two-windows-with-one-draw/11388 "2019-05-19T16:30:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![theo](https://avatars.discourse-cdn.com/v4/letter/t/a87d85/32.png) [@theo](https://discourse.processing.org/u/theo)\
**Post date:** [May 19, 2019, 4:30pm UTC](https://discourse.processing.org/t/two-windows-with-one-draw/11388/1 "2019-05-19T16:30:44Z")

</div>

Hello,  
I managed to create a second window with PApplet and runSketch (even if I haven’t understood every thing) but the draw() of the first and second window don’t seem to be linked: they draw whenever they want (if there is no frame rate specified) no matter if the first (or second) has finished (or not). I need my two draw function running simultaneously, each one waiting that the other has finished.  
I wonder if it is possible to have only one draw for two different windows, something like that:

def draw():  
# window1 part  
rect(…)  
…  
# window2 part  
…

thanks!

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [May 20, 2019, 1:33am UTC](https://discourse.processing.org/t/two-windows-with-one-draw/11388/2 "2019-05-20T01:33:56Z")

</div>

now i would expect generally that an extra window is a separate program!

but if you find the way for 2 programs to communicate,  
also some kind of synchronization can be done.

but also i expect that 2 processing windows run independently  
with 60 FPS drawing something, so  
your wording like

> waiting for one window is finished…

does not fit into processing drawing thinking,  
so actually i assume a complete independent concept issue here.

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [May 20, 2019, 4:30am UTC](https://discourse.processing.org/t/two-windows-with-one-draw/11388/3 "2019-05-20T04:30:18Z")

</div>

- [Forum.Processing.org/two/discussion/16965/how-to-open-a-second-window#Item\_1](http://Forum.Processing.org/two/discussion/16965/how-to-open-a-second-window#Item_1)

---

<div class="post-metadata">

**Author:** ![tabreturn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tabreturn/32/3697_2.png) [@tabreturn](https://discourse.processing.org/u/tabreturn)\
**Post date:** [May 20, 2019, 9:39am UTC](https://discourse.processing.org/t/two-windows-with-one-draw/11388/4 "2019-05-20T09:39:47Z")

</div>

To add to @GoToLoop’s answer, here’s a basic script that demonstrates that the windows do, indeed, stay in sync. Even though the heavy processing load on Window2 causes it to stagger, the progress bar always catches up. I’ve used `frameCount` for controlling the `rect` widths, but you could define and share your own global variables between the windows.

```auto
def setup():
    size(600, 140)
    window2 = Window2()
    switches = '--sketch-path=' + sketchPath(), ''
    PApplet.runSketch(switches, window2)
 
def draw():
    rect(0, 0, frameCount, height)

class Window2(PApplet):
    def settings(w2):
        w2.size(600, 140)

    def draw(w2):
        w2.rect(0, 0, frameCount, w2.height)
        
        # some code to slow down the second window
        # increase/reduce the 1400 for more/less stagger
        for i in range(ceil(random(1400))):
            for j in range(i):
                atan(12345*i) * tan(67890*i)

```

---

<div class="post-metadata">

**Author:** ![theo](https://avatars.discourse-cdn.com/v4/letter/t/a87d85/32.png) [@theo](https://discourse.processing.org/u/theo)\
**Post date:** [May 20, 2019, 8:12pm UTC](https://discourse.processing.org/t/two-windows-with-one-draw/11388/5 "2019-05-20T20:12:36Z")

</div>

Thank you for your answers, I managed to do it using a global variable WTII (Whose Turn Is It), if WTII=1, only the first draw will do something and at the end of the first draw, WTII=2 and only the second draw will do something etc.  
I will try your code @tabreturn tabreturn with a very large range to see if the draws stay synchronised or not.  
Also, it would be interesting to know (if the draws stay synchronised) which one is run 1st or if they are run simultaneously.
