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.
Page Index Toggle Pages: 1
color fade (Read 902 times)
color fade
Feb 10th, 2008, 4:18pm
 
Hi,

I'm working on a program in which colors fade back and forth from blue to black, and then when a switch is triggered (i'm using key-pressed currently until i have the switch hooked up), the blues fade into reds.  i want the red to remain a bright red until the switch is released, when the color will then fade back to blue and then to black.  currently, i have managed to get my blues/blacks working properly, but when i have them fade to red, the reds go up and down from black instead of staying red.  can anyone help me with this dilemma?  my code is below:



int b;
int l;
int v;
int d;

void setup()
{
 size(500,500);            
 background(0,0,255);    
 frameRate(5);

 b=100;
 d=0;
 l=0;
 v=0;
 
}

void draw()
{
if(keyPressed==false)
 
 background(b,0,l);

  if (b>0)
    {
      d=d-10;
    }
 
  if (b<0)
    {
      d=0;
    }

  if (l<10)
    {
      v=v+1;
    }
 
  if (l>250)
    {
      v=v-1;
    }
 
   l=l+v;
   b=b+d;
 
if (keyPressed==true)
 {
   if(key=='r')
   {
    background(b,0,l);

    if (l>10)
     {
       v=v-10;
     }
   
    if (l<0)
     {
       v=0;
     }
 
    if (b<250)
     {
       d=d+20;
     }
   
    if (b>250)
     {
       d=d-20;
     }

b=b+d;
l=l+v;
 
  }
 }
 
 print(b + "\n");
 print(l+"\n");
}
Page Index Toggle Pages: 1