We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Heres's a little program I wrote to test a problem I had in a project I'm working on:
int bg = 0;
int i = 0;
void setup() {
size(790,640);
surface.setResizable(true);
test();
}
void draw() {
}
void keyPressed() {
test();
}
void test() {
surface.setSize(790, 640+10*i);
background(bg);
if (bg == 0) {bg = 50;} else {bg = 0;}
fill(bg);
ellipse(width/2, height/2, 200, 200);
i++;
}
This code should draw a circle in the center of the window every time a key is pressed, along with resizing the window to be 10 pixels longer. However, for some reason the circle stops drawing when I press a key, yet background still changes. This also happens with line() and rect(). The only way I can get the circle to draw is if I put it in the draw() loop, but that will eat CPU. I also tried this in Processing 2 with frame.setSize(), with no luck. Is there an explanation to why this is happening or anything I can do to fix it?
Any help is greatly appreciated!
Answers
We can turn off draw() auto-loop w/ noLoop():
https://processing.org/reference/noLoop_.html
Then call it once w/ redraw() or
redraw = true;
inside keyPressed() for example:https://processing.org/reference/redraw_.html