1
General / Re: How to fade from one colour to another colour?
« on: July 14, 2018, 05:34:34 pm »
I found a solution
Firstly, here's the results:
Transition from orange to white: https://i.imgur.com/1HkZYm8.png?1
Transition from orange to blue: https://i.imgur.com/Z0hnf30.png?1
Turned down the rate so we can see how the colours change: https://i.imgur.com/SIGQJUw.png?1
I don't really think there were too many artifacts and I also did my interpolations entirely in RGB without converting between HSV and RGB (although, I read that converting to HSV produces better results, so I'll probably implement this later at some point).
If anyone in the future is reading this and asking the same questions as me with the fading colours, here's the code I used to do it:
The rate is a float. I have set the rate at 0.02, though for the third image it was set at 0.009.
The formula I found was:
currentColour = (targetColour - currentColour) * rate + currentColour
As you can see in the code this is used 3 times for r, g and b.
Firstly, here's the results:
Transition from orange to white: https://i.imgur.com/1HkZYm8.png?1
Transition from orange to blue: https://i.imgur.com/Z0hnf30.png?1
Turned down the rate so we can see how the colours change: https://i.imgur.com/SIGQJUw.png?1
I don't really think there were too many artifacts and I also did my interpolations entirely in RGB without converting between HSV and RGB (although, I read that converting to HSV produces better results, so I'll probably implement this later at some point).
If anyone in the future is reading this and asking the same questions as me with the fading colours, here's the code I used to do it:
particles[i].colour.r = (255 - particles[i].colour.r) * rate + particles[i].colour.r;
particles[i].colour.g = (255 - particles[i].colour.g) * rate + particles[i].colour.g;
particles[i].colour.b = (255 - particles[i].colour.b) * rate + particles[i].colour.b;
particles[i].colour.g = (255 - particles[i].colour.g) * rate + particles[i].colour.g;
particles[i].colour.b = (255 - particles[i].colour.b) * rate + particles[i].colour.b;
The rate is a float. I have set the rate at 0.02, though for the third image it was set at 0.009.
The formula I found was:
currentColour = (targetColour - currentColour) * rate + currentColour
As you can see in the code this is used 3 times for r, g and b.