Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bga/499141 to your computer and use it in GitHub Desktop.
Save bga/499141 to your computer and use it in GitHub Desktop.
window._bounce1 = function(p){
var value;
for (var a = 0, b = 1; 1; a += b, b /= 2){
if (p >= (7 - 4 * a) / 11){
value = b * b - Math.pow((11 - 6 * a - 11 * p) / 4, 2);
break;
}
}
console.log('n = ', Math.log(b)/Math.log(0.5), 'a = ', a, 'b = ', b);
return value;
};
window._bounce2 = function(t)
{
var n = Math.log(1 - (7 - 11*t)/8)/Math.log(0.5);
console.log('n = ', n);
n = Math.ceil(n);
var b = Math.pow(0.5, n), a = 2*(1 - b);
console.log('n = ', Math.log(b)/Math.log(0.5), 'a = ', a, 'b = ', b);
return b*b - Math.pow((11 - 6*a - 11*t)/4, 2);
};
window._bounce3 = function(t)
{
var b = Math.pow(0.5, Math.ceil(-1.44269*Math.log(0.125 + 1.375*t))), a = 2*(1 - b), k = 3*b - 0.25 - 2.75*t;
console.log('n = ', Math.log(b)/Math.log(0.5), 'a = ', a, 'b = ', b);
return b*b - k*k;
};
window._bounce4 = function(t)
{
var b = Math.pow(0.5, Math.ceil(-1.44269*Math.log(0.125 + 1.375*t))), k = 3*b - 0.25 - 2.75*t;
return b*b - k*k;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment