# Question about changing color over time

**URL:** <https://discourse.processing.org/t/question-about-changing-color-over-time/4093>\
**Category:** Coding Questions\
**Created:** [October 3, 2018, 6:04pm UTC](https://discourse.processing.org/t/question-about-changing-color-over-time/4093 "2018-10-03T18:04:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vincentn20](https://avatars.discourse-cdn.com/v4/letter/v/ec9cab/32.png) [@vincentn20](https://discourse.processing.org/u/vincentn20)\
**Post date:** [October 3, 2018, 6:04pm UTC](https://discourse.processing.org/t/question-about-changing-color-over-time/4093/1 "2018-10-03T18:04:04Z")

</div>

Here is my code

```auto
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.

---

<div class="post-metadata">

**Author:** ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)\
**Post date:** [October 3, 2018, 6:27pm UTC](https://discourse.processing.org/t/question-about-changing-color-over-time/4093/2 "2018-10-03T18:27:43Z")

</div>

Hi vincentn20,

Can you please format.  
Check out this thread to know how to do it: [Guidelines—Tips on Asking Questions](https://discourse.processing.org/t/guidelines-tips-on-asking-questions/2147)

Now for your question, I advise you do go have a look to the [mouseClicked()](https://processing.org/reference/mouseClicked_.html) function and the [lerpColor()](https://processing.org/reference/lerpColor_.html) one.

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