Yo, I hope all is fine for you!
As indicated in the title, I would like to know how background function works in Processing.
What is the difference between the first program (background called before drawing the circle) and the second program (background called after drawing the circle) which is the one "doesn't working"?
int x = 1;
void setup() {
size(400, 400);
background(255);
}
void draw() {
background(255);
circle(200 + x, 200, 20);
x++;
}
int x = 1;
void setup() {
size(400, 400);
background(255);
}
void draw() {
circle(200 + x, 200, 20);
background(255);
x++;
}
background not only defines the background color, but also fills the window with the background color. Therefore you have to call background before drawing the objects of the scene:
void draw() {
background(255);
circle(200 + x, 200, 20);
x++;
}
background clears the window and thereby all previously drawn objects. background does not change a state. When you call background, every pixel in the window is instantly changed.
(Since processing uses OpenGL, glClear is invoked under the hood.)