O'Reilly logo

Java™ Drawing with Apache Batik: A Tutorial by Alexander Kolesnikov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Animation

The simple color change we did in the previous example is some kind of animation, but we can do more. To produce a continuous movement or change of characteristics, normally achieved by a significant number of small successive changes, we use the setInterval method of the window object. This is how you use the method.

var intervalID = setInterval('someFunction()', 50);

In this example, someFunction is called repeatedly with an interval of 50 milliseconds. Note that the setInterval method returns a value that can be used to stop the animation. We stop animation by calling the clearInterval method on the window object.

clearInterval(intervalID);

Listing 8.2 provides an example of animation.

Listing 8.2. Simple animation in an SVG document ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required