Guest User

Untitled

a guest
Jul 21st, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. // send first ball from (0, 0) to (200, 0)
  2. animate(firstBall, 0, 200)();
  3.  
  4. // send second ball from (0, 0) to (100, 0) but with the tempo like it was sent to (200, 0)
  5. animateWithTweak(secondBall, 0, 100, 200)();
  6.  
  7. function animate(ball, start, intended) {
  8. return function () {
  9. ball.animate({cx: intended}, 2000, ">");
  10. }
  11. }
  12.  
  13. function animateWithTweak(ball, start, real, intended) {
  14.  
  15. var distanceRatio = (real - start) / (intended - start);
  16. var timeRatio = 1 - Math.pow(1 - distanceRatio, 1/3);
  17.  
  18. Raphael.easing_formulas["custom"] = function(n) {
  19. var f = Raphael.easing_formulas[">"];
  20. return (1 / distanceRatio) * f(timeRatio * n);
  21. }
  22.  
  23. return function () {
  24. ball.animate({cx: real}, 2000 * timeRatio, "custom");
  25. };
  26. }
Add Comment
Please, Sign In to add comment