Question about changing color over time

Here is my code

int colR = 67;
int colG = 91;
int colB = 155;

void setup()
{
 size(1000, 800);
 frameRate(30);
 background(colR,colG,colB);
 delay(500);
}

void changeNight()
{
 
  if(mousePressed)
  {
   for(int i = 1; i > 0; i++)
   {
    if(colR > 0)
    {
     colR--;
    }
    if(colG > 0)
    {
     colG--;
    }
    if(colB > 0)
    {
     colB--;
    }
   }
  }
  else
  {
   for(int i = 1; i > 0; i++)
   {
    if(colR < 0)
    {
     colR++;
    }
   if(colG < 91)
    {
     colG++;
    }
    if(colB < 155)
    {
     colB++;
    }
   }
  }
 }

I am attempting to make the color of the background slowly change from blue to black while the mouse is pressed and then slowly change back to the same blue when i let go, but currently when i press down the mouse the background stays the same then suddenly changes to black a few seconds later. what i would like to do is make it so when i click the mouse button it will become darker and darker until it reaches black or i click again and then the same to happen from black to blue.

if anyone can figure out what i did wrong or need to add to fix it please help tellmeso i can try to fix it.

1 Like

Hi vincentn20,

Can you please format.
Check out this thread to know how to do it: Guidelines—Tips on Asking Questions

Now for your question, I advise you do go have a look to the mouseClicked() function and the lerpColor() one.

Also I can’t see how your code can work, you miss the basic structure of a processing program.

1 Like