Sign in to follow this  
Servant of the Lord

Reversing an Ease? Ease-In, Ease-Out, Ease-InOut?

Recommended Posts

I'm looking over some easing equations at the moment, and viewing some code, and I got the code written for all the Ease-Ins.

Is there some way I can convert Ease-Ins to Ease-Outs without using entirely new equations?
Can I implement Ease-Outs as:

float EaseOut(blah)
{
    float result = EaseIn(blah);
    return reverse(result);
}

How do I generically reverse a Ease?

Looking at graphs like this, every Ease-Out is just a Ease-In rotated 180 degrees. Surely there's some way to create a function that will reverse any ease?

 

easinggraphs.png

 

All my eases take a value between 0.0 to 1.0, and return a result from 0.0 to 1.0. (Actually, they can be given values less than 0.0 and greater than 1.0 and can return values less than 0.0 and greater than 1.0, but the 0.0 - 1.0 is the scale).

 

I can't just invert the result (1.0f - result), because that'd just flip the ease upside down. It seems I need to invert the position and the result.

 

Does this seem correct:

 

float DoEaseOut(EaseFunction easeFunction, float position)
{
    float result = easeFunction(1.0f - position);
    return 1.0f - result;
}

 

I'm not at a point where I can test the code.

 

Another question is, Ease-InOut seems to be:

if(less than 0.5)
{
   result = EaseIn()
   scale result from (0.0 - 1.0) to (0.0 - 0.5)
}
else
{
   result = EaseOut()
   scale result from (0.0 - 1.0) to (0.5 - 1.0)
}

Is that correct? Looking at some peoples' implementations, that sort-of seems to be what they are doing for some equations, but not for others.

 

So if I have all my easing equations as EaseIn equations, then I can use these:

 

float DoEaseOut(EaseFunction easeFunction, float position)
{
    float result = easeFunction(1.0f - position);
    return 1.0f - result;
}


float DoEaseInOut(EaseFunction easeFunction, float position)
{
    if(position < 0.5f)
    {
        //Do the Ease-In.
        float result = easeFunction(position * 2.0f);
        
        //Scale to (0.0 - 0.5).
        return (result * 0.5f);
    }
    else
    {
        //Do the Ease-Out.
        float result = DoEaseOut(easeFunction, (position * 2.0f) - 1.0f);
        
        //Scale to (0.5 - 1.0).
        return (result * 0.5f) + 0.5f;
    }
}

 

And just pass in the desired Ease-In functions?

Edited by Servant of the Lord

Share this post


Link to post
Share on other sites
alvaro    21266

There is at least one mistake in your code, but your general ideas are correct. You should use your code to generate a few graphs and then you'll find any mistakes easily.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this