I am trying to get a smooth transition between two colours using 2 hexadecimal values. The code I use to do that is this;
this updates 60 times a second, and works. Then the code to calculate the actual colour to draw;
the code all works but something weird happens. When I go, for example, from 0xff_383838 to 0xff_c8c8c8 (those are both 2 different grey colours) in 20 steps, the colours in between are not at all grey. They are purple, orange, green etc. Eventually it ends on the end colour I want. So the last colour is as I want it to be but the colours in between are not the right colours. Does anyone know why this happens and how to fix this? When I entered this colours with the in between steps on a color blender website, the colours in between are all grey, like I want them to be.
You are computing an interpolated color number which includes red, green, and blue all in one integer value. What you need to do is break out each of the RGB values separately and interpolate them separately and finally combine them back into a Color value.
Here's my more verbose attempt. My goal here was to pre-calculate everything possible so that the processing necessary for each step was keep to a minimum. Luc mentioned updating at 60 frames per second but I suspect that's not what it actually works out to be.