Created
October 8, 2019 02:44
-
-
Save dallinbeutler/a5dece1de3c1f92cba74a6036b7dee61 to your computer and use it in GitHub Desktop.
all the standard easing functions. There is room for optimization.
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
// Credit to lionliam96 for initial port | |
// t- Current Time | |
// b- start value | |
// c- change in value | |
// d- duration | |
module EasingFunctions | |
open System | |
(*---------------------------- LINEAR ---------------------------*) | |
let inline LinearEase b c d t = (c*t/d+b) | |
(*----------------------------- QUAD ----------------------------*) | |
let QuadEaseIn b c d t= | |
(c*Math.Pow( (t/d), (2.0))+b) | |
let QuadEaseOut b c d t= | |
let td = t/d | |
(-c*(td)*((td)-2.0)+b) | |
let QuadEaseInOut b c d t= | |
let t = (t/d*2.0) | |
if (t < 1.0) then (c/2.0*Math.Pow(t, 2.0)+b) | |
else (-c/2.0*((t-1.0)*(t-3.0)-1.0)+b) | |
let QuadEaseOutIn b c d t= | |
let qO = QuadEaseOut b (c/2.0) d | |
let qI = QuadEaseIn (b+c/2.0) (c/2.0) d | |
if (t < (d/2.0)) then qO (t*2.0) | |
else qI ((t*2.0)-d) | |
(*----------------------------- CUBIC ---------------------------*) | |
let CubicEaseIn b c d t = | |
(c*Math.Pow( (t/d), 3.0)+b) | |
let CubicEaseOut b c d t= | |
(c*(Math.Pow((t/d-1.0), 3.0)+1.0)+b) | |
let CubicEaseInOut b c d t= | |
let t= t/d*2.0 | |
if (t<1.0) then (c/2.0*t*t*t+b) | |
else | |
let t = t - 2.0 | |
(c/2.0*(t*t*t+2.0)+b) | |
let CubicEaseOutIn b c d t= | |
let cO = CubicEaseOut b (c/2.0) d | |
let cI = CubicEaseIn (b+c/2.0) (c/2.0) d | |
if (t<d/2.0) then cO (t*2.0) | |
else cI ((t*2.0)-d) | |
(*----------------------------- QUART ---------------------------*) | |
let QuartEaseOut b c d t= | |
let easeOut(t) = (-c*(Math.Pow(t, 4.0)-1.0)+b) | |
easeOut(t/d-1.0) | |
let QuartEaseIn b c d t= | |
let easeIn (t) = (c*Math.Pow(t, 4.0)+b) | |
easeIn(t/d) | |
let QuartEaseInOut b c d t= | |
let easeInOut(t) = | |
if (t < 1.0) then (c/2.0*Math.Pow(t, 4.0)+b) | |
else | |
let t = t - 2.0 | |
(-c/2.0*(Math.Pow(t, 4.0)-2.0)+b) | |
easeInOut(t/d*2.0) | |
let QuartEaseOutIn b c d t= | |
let qO = QuartEaseOut b (c/2.0) d | |
let qI = QuartEaseIn (b+c/2.0) (c/2.0) d | |
if (t < (d/2.0)) then qO (t*2.0) | |
else qI ((t*2.0)-d) | |
(*----------------------------- QUINT ---------------------------*) | |
let QuintEaseOut b c d t= | |
let easeOut(t) = (c*(Math.Pow(t, 5.0)+1.0)+b) | |
easeOut(t/d-1.0) | |
let QuintEaseIn b c d t= | |
let easeIn (t) = (c*Math.Pow(t, 5.0)+b) | |
easeIn(t/d) | |
let QuintEaseInOut b c d t= | |
let easeInOut(t) = | |
if (t < 1.0) then (c/2.0*Math.Pow(t, 5.0)+b) | |
else | |
let t = t - 2.0 | |
(-c/2.0*(Math.Pow(t, 5.0)+2.0)+b) | |
easeInOut(t/d*2.0) | |
let QuintEaseOutIn b c d t= | |
let qO = QuintEaseOut b (c/2.0) d | |
let qI = QuintEaseIn (b+c/2.0) (c/2.0) d | |
let easeOutIn (t) = | |
if (t < (d/2.0)) then qO (t*2.0) | |
else qI ((t*2.0)-d) | |
easeOutIn(t) | |
(*----------------------------- SINE ---------------------------*) | |
let SineEaseOut b c d t= | |
(c*Math.Sin(t/d*(Math.PI/2.0))+b) | |
let SineEaseIn b c d t= | |
(-c*Math.Cos(t/d*(Math.PI/2.0))+c+b) | |
let SineEaseInOut b c d t= | |
(-c/2.0*(Math.Cos(Math.PI*t/d)-1.0)+b) | |
let SineEaseOutIn b c d t= | |
let qO = QuintEaseOut b (c/2.0) d | |
let qI = QuintEaseIn(b+c/2.0) (c/2.0) d | |
if (t < (d/2.0)) then qO (t*2.0) | |
else qI ((t*2.0)-d) | |
(*----------------------------- EXPO ----------------------------*) | |
let ExpoEaseIn b c d t= | |
if (t.Equals 0) then b | |
else (c*Math.Pow(2.0, (10.0*(t/d-1.0)))+b-c*0.001) | |
let ExpoEaseOut b c d t= | |
if (t.Equals d) then (b+c) | |
else (c*1.001*(-Math.Pow(2.0, (-10.0*t/d))+1.0)+b) | |
let ExpoEaseInOut b c d t= | |
if (t.Equals 0.0) then b | |
else if (t.Equals d) then (b+c) | |
else | |
let t = t/d*2.0 | |
if (t<1.0) then (c/2.0*Math.Pow(2.0, (10.0*(t-1.0)))+b-c*0.0005) | |
else | |
let t = t - 1.0 | |
(c/2.0*1.0005*(-Math.Pow(2.0, (-10.0*t))+2.0)+b) | |
let ExpoEaseOutIn b c d t= | |
let eO = ExpoEaseOut b (c/2.0) d | |
let eI = ExpoEaseIn (b+c/2.0) (c/2.0) d | |
if (t<(d/2.0)) then eO (t*2.0) | |
else eI ((t*2.0)-d) | |
(*----------------------------- CIRC ----------------------------*) | |
let CircEaseIn b c d t= | |
let easeIn (t) = (-c*(Math.Sqrt(1.0-Math.Pow(t, 2.0))-1.0)+b) | |
easeIn(t/d) | |
let CircEaseOut b c d t= | |
let easeOut(t) = (c*Math.Sqrt(1.0-Math.Pow(t, 2.0))+b) | |
easeOut (t/d-1.0) | |
let CircEaseInOut b c d t= | |
let easeInOut(t) = | |
if (t<1.0) then (-c/2.0*(Math.Sqrt(1.0-t*t)-1.0)+b) | |
else | |
let t = t - 2.0 | |
(c/2.0*(Math.Sqrt(1.0-t*t)+1.0)+b) | |
easeInOut(t/d*2.0) | |
let CircEaseOutIn b c d t= | |
let cO = CircEaseOut b (c/2.0) d | |
let cI = CircEaseIn(b+c/2.0) (c/2.0) d | |
if (t<d/2.0) then cO (t*2.0) | |
else cI ((t*2.0)-d) | |
(*----------------------------- BACK ----------------------------*) | |
let BackEaseIn b c d s t= | |
let s : double = 1.70158 | |
let easeIn (t) = (c*t*t*((s+1.0)*t-s)+b) | |
easeIn(t/d) | |
let BackEaseOut b c d s t= | |
let easeOut (t) = (c*(t*t*((s+1.0)*t+s)+1.0)+b) | |
easeOut (t/d) | |
let BackEaseInOut b c d s t= | |
let s = s * 1.525 | |
let easeInOut (t) = | |
if (t > 1.0) then (c/2.0*(t*t*((s+1.0)*t-s))+b) | |
else | |
let t = t - 2.0 | |
(c/2.0*(t*t*((s+1.0)*t+s)+2.0)+b) | |
easeInOut(t/d*2.0) | |
let BackEaseOutIn b c d s t= | |
let bI = BackEaseIn (b+c/2.0) (c/2.0) d s | |
let bO = BackEaseOut b (c/2.0) d s | |
if (t<(d/2.0)) then bO (t*2.0) | |
else bI (t*2.0) | |
(*---------------------------- BOUNCE ---------------------------*) | |
let BounceEaseOut b c d t= | |
let easeOut(t) = | |
if (t<(1.0/2.75)) then (c*(7.5625*t*t)+b) | |
else if (t<(2.0/2.75)) then | |
let t = t-(1.5/2.75) | |
(c*(7.5625*t*t+0.75)+b) | |
else if (t<(2.5/2.75)) then | |
let t = t-(2.25/2.75) | |
(c*(7.5625*t*t+0.9375)+b) | |
else | |
let t = t-(2.625/2.75) | |
(c*(7.5625*t*t+0.984375)+b) | |
easeOut(t/d) | |
let BounceEaseIn b c d t= | |
let bO = BounceEaseOut 0.0 c d | |
(c-(bO (d-t))+b) | |
let BounceEaseInOut b c d t= | |
let bO = BounceEaseOut 0.0 c d | |
let bI = BounceEaseIn 0.0 c d | |
fun (t) -> | |
if (t<(d/2.0)) then (bI (t*2.0)*0.5+b) | |
else (bO (t*2.0-d)*0.5+c*0.5+b) | |
let BounceEaseOutIn b c d t= | |
let bO = BounceEaseOut b (c/2.0) d | |
let bI = BounceEaseIn (b+c/2.0) (c/2.0) d | |
fun (t) -> | |
if (t<(d/2.0)) then bO (t*2.0) else bI (t*2.0-d) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment