I like to write simple pieces of code without a draw() block. In this way, it often doesn’t even have to be surrounded by the setup() function, since Processing will do that behind the scenes.
When I brought over an old sketch to P3, I had to use surface.setSize() instead of size() to adjust the display window to something I opened on the fly. To my surpise, I got an empy the display window.
An example code:
surface.setSize(400, 200);
ellipse(10, 10, 20, 20);
This has been brought up 2 years ago here:
Can’t draw anything just after using surface.setSize()
The conclusion of the accepted answer was:
The surface.setSize() is done at next draw() loop.
Yet if I add a 4s delay the circle will appear as an enlarged ellipse for 4s:
surface.setSize(400, 200);
ellipse(10, 10, 20, 20);
delay(4000);
The zooming effect seems to have a reference to an “ideal” 100 x 100 sized window. Let’s try that as well:
surface.setSize(100, 100);
ellipse(10, 10, 20, 20);
delay(4000);
Oops, the circle will not disappear after 4s! What is going on?
Now everything will look fine after 4s if I follow jeremydouglass’s advice (from the above quoted topic) to “move all drawing code to draw()…”:
void setup() {
surface.setSize(400, 200);
ellipse(10, 10, 20, 20);
delay(4000);
noLoop();
}
void draw() {
ellipse(10, 10, 20, 20);
}
Of course jeremydouglass meant this:
void setup() {
surface.setSize(400, 200);
noLoop();
}
void draw() {
ellipse(10, 10, 20, 20);
}
Thanks.