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:
# window1 part
# window2 part
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.
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.
window2 = Window2()
switches = '--sketch-path=' + sketchPath(), ''
rect(0, 0, frameCount, height)
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)
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.