About Store Forum Documentation Contact



Post Reply 
How use function ColorLerp
Author Message
Harton Offline
Member

Post: #1
How use function ColorLerp
I would like change object color from colorMin to colorMax and vice versa from colorMax to colorMin. I use function ColorLerp but this function work oddly.
Example:
Code:
// in class declaration
Color color, colorMin, colorMax;
bool up;

// in class function - update()
if(up == true)
{
    color = ColorLerp(color, colorMax, 0.5);

    if(color==colorMax)
        up = false;
}
else
{
    color = ColorLerp(color, colorMin, 0.5);

    if(color==colorMin)
        up = true;
}

object.color = color.asVec4();

What is wrong? Variable 'up' never change...
05-23-2011 12:38 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Driklyn Offline
Member

Post: #2
RE: How use function ColorLerp
I would recommend using a timer-based solution:

Code:
Flt colorStep;

Bool update()
{
    colorStep += Time.d() * ((up) ? 1 : -1);
    Clamp(colorStep, 0, 1);

    color = ColorLerp(colorMin, colorMax, colorStep);

    // ...
}
05-23-2011 06:05 AM
Find all posts by this user Quote this message in a reply
Harton Offline
Member

Post: #3
RE: How use function ColorLerp
Thanks!
A small fix and it's working.
05-23-2011 08:51 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Post Reply