Skip to content

Instantly share code, notes, and snippets.

@sphynx
Created February 2, 2011 16:04
Show Gist options
  • Save sphynx/807908 to your computer and use it in GitHub Desktop.
Save sphynx/807908 to your computer and use it in GitHub Desktop.
Tweaking Raphael easing function ">"
// send first ball from (0, 0) to (200, 0)
animate(firstBall, 0, 200)();
// send second ball from (0, 0) to (100, 0) but with the tempo like it was sent to (200, 0)
animateWithTweak(secondBall, 0, 100, 200)();
function animate(ball, start, intended) {
return function () {
ball.animate({cx: intended}, 2000, ">");
}
}
function animateWithTweak(ball, start, real, intended) {
var distanceRatio = (real - start) / (intended - start);
var timeRatio = 1 - Math.pow(1 - distanceRatio, 1/3);
Raphael.easing_formulas["custom"] = function(n) {
var f = Raphael.easing_formulas[">"];
return (1 / distanceRatio) * f(timeRatio * n);
}
return function () {
ball.animate({cx: real}, 2000 * timeRatio, "custom");
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment