For the last Ludum Dare, I wanted to have a nice effect on the background of my puzzle game in order to change the color based on the action on the board.
First we have to get the initial color (color1) and the new one (color2). In order to change the color smoothly, we will do it with a Timer object.
Here is the RGB typedef:
The first step is the calculate the distance between those two colors (all methods are based on the RGB type):
Now that we have the difference, we have to calculate the value that will determine how the color will change between each step:
The INCREMENT_VALUE value allows use to determine how we want the effect to change. The higher the value is, the quicker the effect will be.
I've set it to 100.
Now we have to calculate the new color :
And same thing for each tone.
I'll now add this step to the Timer object.
I'm using the Timer class in order to have a cross platform method. But you can use any kind of listener or Signal.
In this loop, you'll have to change the property of your object.
Where rgb2hex transform the RGB object in hexa :
Here is an example :