Learning Scientific Programming with Python (2nd edition)
P4.4.3: Creating a set of SVG image files
Question P4.4.3
Write a Python program to create a directory, test
in the user's home directory and to populate it with 20 SVG files depicting a small, filled red circle inside a large, black, unfilled circle, for example:
<?xml version="1.0" encoding="utf-8"?>
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
width="500" height="500" style="background: #ffffff">
<circle cx="250.0" cy="250.0" r="200" style="stroke: black; stroke-width: 2px; fill: none;"/>
<circle cx="430.0" cy="250.0" r="20" style="stroke: red; fill: red;"/>
</svg>
Each file should move the red circle around the inside rim of the larger circle so that the 20 files together could form an animation.
One way to achieve this using the free ImageMagick software. Ensure the SVG files are named: fig00.svg
, fig01.svg
, etc. and issue the following command from your operating system's command line:
$ convert -delay 5 -loop 0 fig*.svg animation.gif
to produce an animated GIF image.