Last active
August 29, 2015 13:57
-
-
Save milichev/9415760 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(function(math) { | |
"use strict"; | |
function ease(value, start, end, pow) { | |
/// <summary> | |
/// Returns eased value for the input in the [start..end] range. | |
/// </summary> | |
/// <param name="value">Input value in the [start..end] range to ease.</param> | |
/// <param name="start">Value range start, default 0.</param> | |
/// <param name="end">Value range end, default 1.</param> | |
/// <param name="pow">Easing power factor, default 2.</param> | |
return get(start, end, pow)(value); | |
} | |
function get(start, end, pow) { | |
/// <summary> | |
/// Returns an easing function for input value in the [start..end] range. | |
/// </summary> | |
/// <param name="start">Value range start, default 0.</param> | |
/// <param name="end">Value range end, default 1.</param> | |
/// <param name="pow">Easing power factor, default 2.</param> | |
switch (arguments.length) { | |
case 0: | |
start = 0; | |
end = 1; | |
pow = 2; | |
break; | |
case 1: | |
end = start; | |
start = 0; | |
pow = 2; | |
break; | |
case 2: | |
pow = 2; | |
break; | |
} | |
if (!isFinite(pow) || !(pow > 0)) { | |
pow = 2; | |
} | |
if (!isFinite(start)) { | |
start = 0; | |
} | |
if (!isFinite(end)) { | |
end = 1; | |
} | |
if (start > end) { | |
start = end; | |
} | |
return function(value) { | |
return unchecked(value, start, end, pow); | |
}; | |
} | |
function unchecked(value, start, end, pow) { | |
var ratio = math.pow(value, pow) / (math.pow(value, pow) + math.pow(1 - value, pow)); | |
return start + (end - start) * ratio; | |
} | |
math.ease = ease; | |
math.ease.get = get; | |
})(Math); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment