Skip to content

Instantly share code, notes, and snippets.

@tomgidden
Created May 18, 2020 14:40
Show Gist options
  • Save tomgidden/d728b74209394d6163790f266c1d11ba to your computer and use it in GitHub Desktop.
Save tomgidden/d728b74209394d6163790f266c1d11ba to your computer and use it in GitHub Desktop.
Custom easing functions
const easeOutSpring = (t, b, c, d) => {
const SP_zeta = 0.93;
const SP_omega0 = 6.74;
const SP_omegaD = 17.391;
const SP_A = 0.54;
const SP_B = -0.27;
const SP_scale = -0.013513;
const SP_cutoffY = 0.20236;
const SP_cutoffX = 0.91216;
const SP_scaleY = 0.26756;
const x = t/d;
const Q = 1-Math.cos(x*Math.PI/2);
const W = (x-SP_cutoffX)/SP_cutoffX;
const Z = Math.exp(-SP_zeta*SP_omega0*W) * (SP_A*Math.cos(SP_omegaD*W)+SP_B*Math.sin(SP_omegaD*W));
const xx = (Q<SP_cutoffY) ? Q/SP_scaleY : (1 - Z*SP_scale);
return xx*c + b;
};
const easeInExpoBias = (t, b, c, d) => {
const bias = 0.3;
return (t==0) ? b : c * Math.pow(2, 10 * (0.3+((1-0.3)*t)/d - 1)) + b - c * 0.001;
};
const easeOutSingleBounce = (t, b, c, d) => {
const ts = (t/=d)*t;
const tc = ts*t;
const val = b+c*(-3.7475*tc*ts + 2.0475*ts*ts + 2.7*tc);
return (val>1) ? (2-val) : val;
};
const easeOutTinyBack = (t, b, c, d) => {
const ts = (t/=d)*t;
const tc = ts*t;
const val = b+c*(-3.1975*tc*ts + 3.0975*ts*ts + 1.1*tc);
return val;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment