We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › changing the background without refreshing
Page Index Toggle Pages: 1
changing the background without refreshing (Read 355 times)
changing the background without refreshing
Nov 16th, 2007, 1:18pm
 
Hi there, Here's what I'd like to do: I have a sketch that draws random curves all over the window and I'd like the background to change colours smoothly during the accumulation of the curves WITHOUT clearing the screen/erasing the curves... how would I do this? Thank you.
D.S
Re: changing the background without refreshing
Reply #1 - Nov 16th, 2007, 3:46pm
 
In the draw() function, the background color is used to clear the display window at the beginning of each frame.

If you wish to change the color of the background without clearing the screen, I believe the best way to do so is to create a rectangle the size of the screen size and to draw it on a negative layer. By default, everything is drawn on layer "0" so if you draw a rectangle on layer "-1", whatever is drawn on top won't be erased. To do so, you need to be either in P3D or OPENGL.


The example below changes the background from black to white, and when the color reaches 255, right back to black. It's up to you to change the variable in the fill() to reflect the color you want. It draws red squares randomly to show you that nothing gets erased.

Code:

int bgColor = 0;

void setup() {
size(800,800, P3D);
background(0);
}

void draw() {
pushMatrix();
translate(0,0,-1);
fill(bgColor %255);
rect(0,0,width,height);
popMatrix();

bgColor +=5;

fill(255,0,0);
rect(int(random(width)), int(random(height)), 10,10);
}


Hope it helps!
Page Index Toggle Pages: 1