Skip to content

Commit

Permalink
Revert ease interface.
Browse files Browse the repository at this point in the history
Related #13.
  • Loading branch information
mbostock committed Feb 4, 2016
1 parent 30dda36 commit 8ddb9de
Show file tree
Hide file tree
Showing 22 changed files with 693 additions and 713 deletions.
102 changes: 51 additions & 51 deletions README.md

Large diffs are not rendered by default.

51 changes: 30 additions & 21 deletions src/back.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,37 @@
var overshoot = 1.70158;

export var backIn = (function backIn(s) {
return s = +s, {
overshoot: backIn,
ease: function(t) {
return t * t * ((s + 1) * t - s);
}
};
export var backIn = (function custom(s) {
s = +s;

function backIn(t) {
return t * t * ((s + 1) * t - s);
}

backIn.overshoot = custom;

return backIn;
})(overshoot);

export var backOut = (function backOut(s) {
return s = +s, {
overshoot: backOut,
ease: function(t) {
return --t * t * ((s + 1) * t + s) + 1;
}
};
export var backOut = (function custom(s) {
s = +s;

function backOut(t) {
return --t * t * ((s + 1) * t + s) + 1;
}

backOut.overshoot = custom;

return backOut;
})(overshoot);

export var backInOut = (function backInOut(s) {
return s = +s, {
overshoot: backInOut,
ease: function(t) {
return ((t *= 2) < 1 ? t * t * ((s + 1) * t - s) : (t -= 2) * t * ((s + 1) * t + s) + 2) / 2;
}
};
export var backInOut = (function custom(s) {
s = +s;

function backInOut(t) {
return ((t *= 2) < 1 ? t * t * ((s + 1) * t - s) : (t -= 2) * t * ((s + 1) * t + s) + 2) / 2;
}

backInOut.overshoot = custom;

return backInOut;
})(overshoot);
24 changes: 8 additions & 16 deletions src/bounce.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,14 @@ var b1 = 4 / 11,
b9 = 63 / 64,
b0 = 1 / b1 / b1;

function bounce(t) {
return (t = +t) < b1 ? b0 * t * t : t < b3 ? b0 * (t -= b2) * t + b4 : t < b6 ? b0 * (t -= b5) * t + b7 : b0 * (t -= b8) * t + b9;
export function bounceIn(t) {
return 1 - bounceOut(1 - t);
}

export var bounceIn = {
ease: function(t) {
return 1 - bounce(1 - t);
}
};

export var bounceOut = {
ease: bounce
};
export function bounceOut(t) {
return (t = +t) < b1 ? b0 * t * t : t < b3 ? b0 * (t -= b2) * t + b4 : t < b6 ? b0 * (t -= b5) * t + b7 : b0 * (t -= b8) * t + b9;
}

export var bounceInOut = {
ease: function(t) {
return ((t *= 2) <= 1 ? 1 - bounce(1 - t) : bounce(t - 1) + 1) / 2;
}
};
export function bounceInOut(t) {
return ((t *= 2) <= 1 ? 1 - bounceOut(1 - t) : bounceOut(t - 1) + 1) / 2;
}
24 changes: 9 additions & 15 deletions src/circle.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
export var circleIn = {
ease: function(t) {
return 1 - Math.sqrt(1 - t * t);
}
};
export function circleIn(t) {
return 1 - Math.sqrt(1 - t * t);
}

export var circleOut = {
ease: function(t) {
return Math.sqrt(1 - --t * t);
}
};
export function circleOut(t) {
return Math.sqrt(1 - --t * t);
}

export var circleInOut = {
ease: function(t) {
return ((t *= 2) <= 1 ? 1 - Math.sqrt(1 - t * t) : Math.sqrt(1 - (t -= 2) * t) + 1) / 2;
}
};
export function circleInOut(t) {
return ((t *= 2) <= 1 ? 1 - Math.sqrt(1 - t * t) : Math.sqrt(1 - (t -= 2) * t) + 1) / 2;
}
24 changes: 9 additions & 15 deletions src/cubic.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
export var cubicIn = {
ease: function(t) {
return t * t * t;
}
};
export function cubicIn(t) {
return t * t * t;
}

export var cubicOut = {
ease: function(t) {
return --t * t * t + 1;
}
};
export function cubicOut(t) {
return --t * t * t + 1;
}

export var cubicInOut = {
ease: function(t) {
return ((t *= 2) <= 1 ? t * t * t : (t -= 2) * t * t + 2) / 2;
}
};
export function cubicInOut(t) {
return ((t *= 2) <= 1 ? t * t * t : (t -= 2) * t * t + 2) / 2;
}
58 changes: 32 additions & 26 deletions src/elastic.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,43 @@ var tau = 2 * Math.PI,
amplitude = 1,
period = 0.3;

export var elasticIn = (function elasticIn(a, p) {
export var elasticIn = (function custom(a, p) {
var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
return {
amplitude: function(a) { return elasticIn(a, p * tau); },
period: function(p) { return elasticIn(a, p); },
ease: function(t) {
return a * Math.pow(2, 10 * --t) * Math.sin((s - t) / p);
}
};

function elasticIn(t) {
return a * Math.pow(2, 10 * --t) * Math.sin((s - t) / p);
}

elasticIn.amplitude = function(a) { return custom(a, p * tau); };
elasticIn.period = function(p) { return custom(a, p); };

return elasticIn;
})(amplitude, period);

export var elasticOut = (function elasticOut(a, p) {
export var elasticOut = (function custom(a, p) {
var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
return {
amplitude: function(a) { return elasticOut(a, p * tau); },
period: function(p) { return elasticOut(a, p); },
ease: function(t) {
return 1 - a * Math.pow(2, -10 * (t = +t)) * Math.sin((t + s) / p);
}
};

function elasticOut(t) {
return 1 - a * Math.pow(2, -10 * (t = +t)) * Math.sin((t + s) / p);
}

elasticOut.amplitude = function(a) { return custom(a, p * tau); };
elasticOut.period = function(p) { return custom(a, p); };

return elasticOut;
})(amplitude, period);

export var elasticInOut = (function elasticInOut(a, p) {
export var elasticInOut = (function custom(a, p) {
var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
return {
amplitude: function(a) { return elasticInOut(a, p * tau); },
period: function(p) { return elasticInOut(a, p); },
ease: function(t) {
return ((t = t * 2 - 1) < 0
? a * Math.pow(2, 10 * t) * Math.sin((s - t) / p)
: 2 - a * Math.pow(2, -10 * t) * Math.sin((s + t) / p)) / 2;
}
};

function elasticInOut(t) {
return ((t = t * 2 - 1) < 0
? a * Math.pow(2, 10 * t) * Math.sin((s - t) / p)
: 2 - a * Math.pow(2, -10 * t) * Math.sin((s + t) / p)) / 2;
}

elasticInOut.amplitude = function(a) { return custom(a, p * tau); };
elasticInOut.period = function(p) { return custom(a, p); };

return elasticInOut;
})(amplitude, period);
24 changes: 9 additions & 15 deletions src/exp.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
export var expIn = {
ease: function(t) {
return Math.pow(2, 10 * t - 10);
}
};
export function expIn(t) {
return Math.pow(2, 10 * t - 10);
}

export var expOut = {
ease: function(t) {
return 1 - Math.pow(2, -10 * t);
}
};
export function expOut(t) {
return 1 - Math.pow(2, -10 * t);
}

export var expInOut = {
ease: function(t) {
return ((t *= 2) <= 1 ? Math.pow(2, 10 * t - 10) : 2 - Math.pow(2, 10 - 10 * t)) / 2;
}
};
export function expInOut(t) {
return ((t *= 2) <= 1 ? Math.pow(2, 10 * t - 10) : 2 - Math.pow(2, 10 - 10 * t)) / 2;
}
8 changes: 3 additions & 5 deletions src/linear.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export var linear = {
ease: function(t) {
return +t;
}
};
export function linear(t) {
return +t;
}
51 changes: 30 additions & 21 deletions src/poly.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,37 @@
var exponent = 3;

export var polyIn = (function polyIn(e) {
return e = +e, {
exponent: polyIn,
ease: function(t) {
return Math.pow(t, e);
}
};
export var polyIn = (function custom(e) {
e = +e;

function polyIn(t) {
return Math.pow(t, e);
}

polyIn.exponent = custom;

return polyIn;
})(exponent);

export var polyOut = (function polyOut(e) {
return e = +e, {
exponent: polyOut,
ease: function(t) {
return 1 - Math.pow(1 - t, e);
}
};
export var polyOut = (function custom(e) {
e = +e;

function polyOut(t) {
return 1 - Math.pow(1 - t, e);
}

polyOut.exponent = custom;

return polyOut;
})(exponent);

export var polyInOut = (function polyInOut(e) {
return e = +e, {
exponent: polyInOut,
ease: function(t) {
return ((t *= 2) <= 1 ? Math.pow(t, e) : 2 - Math.pow(2 - t, e)) / 2;
}
};
export var polyInOut = (function custom(e) {
e = +e;

function polyInOut(t) {
return ((t *= 2) <= 1 ? Math.pow(t, e) : 2 - Math.pow(2 - t, e)) / 2;
}

polyInOut.exponent = custom;

return polyInOut;
})(exponent);
24 changes: 9 additions & 15 deletions src/quad.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
export var quadIn = {
ease: function(t) {
return t * t;
}
};
export function quadIn(t) {
return t * t;
}

export var quadOut = {
ease: function(t) {
return t * (2 - t);
}
};
export function quadOut(t) {
return t * (2 - t);
}

export var quadInOut = {
ease: function(t) {
return ((t *= 2) <= 1 ? t * t : --t * (2 - t) + 1) / 2;
}
};
export function quadInOut(t) {
return ((t *= 2) <= 1 ? t * t : --t * (2 - t) + 1) / 2;
}
24 changes: 9 additions & 15 deletions src/sin.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
var pi = Math.PI,
halfPi = pi / 2;

export var sinIn = {
ease: function(t) {
return 1 - Math.cos(t * halfPi);
}
};
export function sinIn(t) {
return 1 - Math.cos(t * halfPi);
}

export var sinOut = {
ease: function(t) {
return Math.sin(t * halfPi);
}
};
export function sinOut(t) {
return Math.sin(t * halfPi);
}

export var sinInOut = {
ease: function(t) {
return (1 - Math.cos(pi * t)) / 2;
}
};
export function sinInOut(t) {
return (1 - Math.cos(pi * t)) / 2;
}
Loading

0 comments on commit 8ddb9de

Please sign in to comment.