Author Topic: Red to Another Color [Solved]  (Read 1511 times)

I need help figuring out how to smoothly transition from red to any other color, using 0-1 RGBA values. It'll always start at 1 0 0, with the alpha depending on how damaged the player is. And then it needs to transition to any other color, even the alpha. The time that it has to transition is also based on how damaged the player is.

Just straight from one color to the next.
Like this:


Not like this:
« Last Edit: March 30, 2016, 04:38:45 PM by jes00 »

have r slide from 255 to 0
g slide from 0 to 255
both change at the same time and same rate

probably not exactly what you're looking for; i recall there being a set of linear equations i found online once. look up using code to transition colors and stuff, probably on stack exchange
« Last Edit: March 30, 2016, 03:51:17 PM by Conan »

I'm confused, what is the problem? You need to do a linear interpolation on each channel.


I guess you can use the vector functions to make it more efficient:

function interpolateColor(%col1, %col2, %d)
{
   //get alpha
   %alpha1 = getWord(%col1, 3);
   %alpha2 = getWord(%col2, 3);

   //get new color
   return vectorAdd(%col1, vectorScale(vectorSub(%col2, %coil1), %d)) SPC
      %alpha1 + (%alpha2 - %alpha1) * %d;
}

Thanks Zeblote! That's exactly what I needed.