I have a background for my title screen of my program, and want the colour of it to slowly change over time. This is how the background's drawn:
g.setColor(255, 0, 0);
g.fillRect(0, 0, 640, 480); //g is the Graphics Object
So at the moment, the background's red. I want it to slowly fade to green, then blue, and then back to red. I have tried this:
int red = 255;
int green = 0;
int blue = 0;
long timer = System.nanoTime();
long elapsed = (System.nanoTime() - timer) / 1000000;
if(elapsed > 100) {
red--;
green++;
blue++;
}
g.setColor(red, green, blue);
g.fillRect(0, 0, 640, 480);
I did have more code to make it so if any of the values reached 0, they would be added to and if they reached 255 they would be subtracted, but you get the idea. And this was in a render method which was called 60 times a second. (the timer variable was created outside of the render method)
Thanks!