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
…
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.
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)
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.