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 1273 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 10th, 2010, 1:15pm
 
Just use a variable for the size of the increment to use when decreasing the fill colour. e.g. float colourincrement =1; also have a variable for the fill colour eg.  color fillcolour;

Then just have a fillcolour-=colourincrement; statement in draw(), and draw the rectangle.

Your slider could then be linked to the colourincrement variable.

Something like this:

Code:
color fillcolour=255;
float colourincrement=1;

void setup()
{
 size(400, 400);
 frameRate(30);
 smooth();
 noStroke();
 background(0);
}

void draw()
{
 background(0);
 fill(fillcolour);
 rect(width/2, height/2, 100, 100);
 if (fillcolour>0) fillcolour-=colourincrement;
}


to do background:

Code:
void draw()
{
if (fillcolour>0) fillcolour-=colourincrement;
background(fillcolour);
}


Page Index Toggle Pages: 1