Created
January 27, 2020 05:09
-
-
Save spencersalazar/15c76d37d603613dc3d539d4032abc54 to your computer and use it in GitHub Desktop.
Generic easing function with tweakable power and midpoint.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Ease in/out function with settable power and midpoint. | |
Use p parameter to adjust speed at endpoints (cubic: p=3, quartic: p=4) | |
Midpoint is point at which speed is fastest and uneased. | |
@param t time or independent variable in range [0,1]. Input should be scaled to this range from whatever source range is expected. | |
@param p power, e.g. quadratic=2, cubic=3. Non-integral powers can be used to fine-tune the curve. | |
@param mid midpoint of curve, where it is "most linear". | |
@return output value in range [0,1]. Can be multiplied to scale to desired range. | |
*/ | |
inline float easeInOut(float t, float p = 3.f, float mid = 0.5f) | |
{ | |
if (t < mid) { | |
return powf(t/mid, p)*mid; | |
} else { | |
return 1.f-powf((1.f-t)/(1-mid), p)*(1-mid); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment