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 & HelpPrograms › Help On slowly Fading the bg from white to black!
Page Index Toggle Pages: 1
Help On slowly Fading the bg from white to black! (Read 769 times)
Help On slowly Fading the bg from white to black!
Jan 5th, 2010, 5:05pm
 
Hi!

First i like to state that im new to processing.

What i try to achieve is to have the background or a rect to slowly fade from white to black.

I understand how to do this with the for loop or even in  the draw function itself but i want to be able to alter speed of how long time it takes for it to fade from white to black.

I am a bit familiar with the controlP5 lib and will probably use a slider from this lib to alter the speed of the fade.

Ive been playing around with programs like quartz composer and there you have an interpolation or lfo function where you can set the time it takes to get from one value to another but cant get my head around how to set this up in processing.

Best regards

niklas
Re: Help On slowly Fading the bg from white to black!
Reply #1 - Jan 6th, 2010, 1:40am
 
Well you want to get from fill(255) to fill(0)...  This is one crude approach:

Code:
float fillColour = 255;
float increment = 1.5;

void setup() {
size(100,100);

}

void draw() {
background(int(fillColour));
if(fillColour >0){
fillColour -= increment;
}
}


I'm sure there's an interpolation library floating around somewhere too...
Re: Help On slowly Fading the bg from white to black!
Reply #2 - Jan 6th, 2010, 6:09am
 
Similarly to as blindfish suggested, you could do so on a rectangle (even one that covers the screen).  I draw a scene and then a rectangle the size of the screen, then fade the rectangle alpha until transparent, giving the sketch a nice fade in effect.  For a rectangle, you would just modify the fill before the rect();
Code:
fill(fillColour);
rect(30, 20, 55, 55);
Page Index Toggle Pages: 1