Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ease-in and ease-out animation formula

Say, if I'm doing the Ease-Out and then Ease-In animation of an object's movement from X1 coordinate to X2 coordinate over S steps at equal time intervals. Can some suggest the formula to calculate this movement's X coordinates?

like image 546
ahmd0 Avatar asked Nov 19 '12 20:11

ahmd0


People also ask

What is ease in and ease out in animation?

In classic animation, the term for motion that starts slowly and accelerates is "slow in," and for motion that starts quickly and decelerates is "slow out." The terminology most commonly used on the web for these are “ease in” and “ease out,” respectively.

What is the difference between Ease In and Ease Out?

Ease-In: Causes the animation to start more quickly than linear ones, and it also has deceleration at the end. Ease Out: This is the opposite of Ease-In. Animation starts slow and ends fast. Ease In Out: Slow start, fast middle, and slow end.

What is ease in in 2d animation?

As the name implies, ease in eases the character or object into the motion, ease out eases the character or object out of the motion.


1 Answers

Personally, I'd rather use a function that gets a time in [0; 1] and output a value in [0; 1], so that we can apply the result to any type (2D vector, 3D vector, ...).

Solution 1

For the quadratic easing in/out, the curve is separated in two distinct functions depending on the value of t:

  • when t <= 0.5: f(x) = 2 * x * x with x in [0;0.5] (graph)
  • when t > 0.5: f(x) = 2 * x * (1 - x) + 0.5 with x in [0;0.5] (graph)

Here are the graphs:

graph - part 1
graph - part 2

Since the second function is also in [0;0.5], but t > 0.5 when we start to use it, we need to reduce t by 0.5.

This is the result, in C:

float InOutQuadBlend(float t) {     if(t <= 0.5f)         return 2.0f * t * t;     t -= 0.5f;     return 2.0f * t * (1.0f - t) + 0.5f; } 

Solution 2 (Bézier)

Another interesting blend curve is the one given by Bézier, which have the advantage to be quite optimized (no if). Here is the curve from Wolfram:

Bezier curve

And here is the C code:

float BezierBlend(float t) {     return t * t * (3.0f - 2.0f * t); } 

Solution 3 (parametric function)

Another method proposed by @DannyYaroslavski is the simple formula proposed here.

It is parametric and gets a nice in/out acceleration and deceleration.

With alpha = 2, you get this function:

curve

Which translates in C like this:

float ParametricBlend(float t) {     float sqt = t * t;     return sqt / (2.0f * (sqt - t) + 1.0f); } 

Edit 1: Add solution 3 from @DannyYaroslavski
Edit 2: Better explanation for solution 1
Edit 3: Add graphs to all solutions

like image 76
Creak Avatar answered Sep 16 '22 13:09

Creak