Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combining Animations in Raphael

I am animating a SVG "gear/cog" shape infinitely so that it spins endlessly, as follows:

gearAnim = Raphael.animation({ transform: rotation }, duration, 'linear');
which.animate(gearAnim.repeat("Infinity")); // rotate infinitely.

If I want to make the gear pulse (scale transformation) I do the following:

value.animate({
   2: { transform: "s1.2" },
   3: { transform: "s1"} 
}, 600, 'easeOut');

This works. However, the problem is that the scale transformation does not happen with the gear rotation. It stops animating, resets to rotation 0, scales, then jerks back into the previous animation.

Is there a a way of allowing the shape to scale once while also rotating infinitely? Is there something I'm missing here?

Thanks a lot.

like image 390
specik Avatar asked Mar 07 '26 17:03

specik


1 Answers

Not sure if that's the best way, but one option is to set the callback: http://jsfiddle.net/b9akz/106/

var paper = new Raphael('holder');
var box = paper.rect(100, 100, 30, 30).attr({ stroke: "darkgreen" });
var scale = 2;
var angle = 0;
var func = function(){
    scale = scale > 1.5 ? 1 : 2; 
    angle = angle + 120;
    box.animate(Raphael.animation({ transform: "s" + scale + " r" + angle }, 1000, 'linear', func), 1);
};
func();

There's some artifact in the beginning, though, -- it seems to only start scaling after the first rotation cycle is over.

like image 188
Qnan Avatar answered Mar 10 '26 07:03

Qnan