Ease Bounce in and out. - CSharp System

CSharp examples for System:Math Easing Function

Description

Ease Bounce in and out.

Demo Code


using System;/*  w  w w  .  j  a  va  2 s .  c o m*/

public class Main{
        const float PI = 3.14159f;
        const float PI2 = PI / 2;
        const float B1 = 1 / 2.75f;
        const float B2 = 2 / 2.75f;
        const float B3 = 1.5f / 2.75f;
        const float B4 = 2.5f / 2.75f;
        const float B5 = 2.25f / 2.75f;
        const float B6 = 2.625f / 2.75f;
        /// <summary>
        /// Bounce in and out.
        /// </summary>
        /// <param name="t">Time elapsed.</param>
        /// <returns>Eased timescale.</returns>
        public static float BounceInOut(float t) {
            if (t < .5) {
                t = 1 - t * 2;
                if (t < B1) return (float)((1 - 7.5625 * t * t) / 2);
                if (t < B2) return (float)((1 - (7.5625 * (t - B3) * (t - B3) + .75)) / 2);
                if (t < B4) return (float)((1 - (7.5625 * (t - B5) * (t - B5) + .9375)) / 2);
                return (float)((1 - (7.5625 * (t - B6) * (t - B6) + .984375)) / 2);
            }
            t = t * 2 - 1;
            if (t < B1) return (float)((7.5625 * t * t) / 2 + .5);
            if (t < B2) return (float)((7.5625 * (t - B3) * (t - B3) + .75) / 2 + .5);
            if (t < B4) return (float)((7.5625 * (t - B5) * (t - B5) + .9375) / 2 + .5);
            return (float)((7.5625 * (t - B6) * (t - B6) + .984375) / 2 + .5);
        }
}

Related Tutorials