XML technologies / SVG / Using animations / Ways to implement animations / Adjusting colors with animateColor
(Excerpt from “Das Einsteigerseminar SVG — Webgrafiken mit XML” by Helma Spona)
As this chapter’s first example showed, the tag <animateColor> animates an element’s fill or border color. It has only the universal animation attributes, but some special points apply. Assign color values to the attributes from, by and to, and the values list must also contain semicolon-separated color values.
The values attribute specifies the colors displayed in sequence. With starting and final colors specified by from and to, unlike a values value list, you cannot choose intermediate values. The next example demonstrates this by changing text fill or outline colors with different animations.
The first animation blends blue to red, with calcMode="discrete" displaying the result only after the animation ends. The second also blends blue to red, but omits calcMode, so transitions are visible.
The third animation uses the values attribute to specify individual colors and the keyTimes attribute to determine after how many seconds this happens. The final two animations both affect the last text, changing fill and outline colors in opposite directions.
Note:
Instead of color names, you can also use the rgb instruction.
<defs>
<animateColor xlink:href="#text1" dur="6s" from="blue" to="red" attributeName="fill" calcMode="discrete" fill="freeze"/>
<animateColor xlink:href="#text2" dur="6s" from="blue" to="red" attributeName="fill" fill="freeze"/>
<animateColor xlink:href="#text3" dur="6s" begin="4s" values="blue;red;green;blue;white;yellow;red" keyTimes="0;1;1.5;2;3;3.5;4" attributeName="fill" fill="freeze"/>
<animateColor xlink:href="#text4" dur="6s" begin="4s" from="blue" to="red" attributeName="fill" fill="freeze"/>
<animateColor xlink:href="#text4" dur="6s" begin="4s" from="red" to="blue" attributeName="stroke" fill="freeze"/>
</defs>
<text x="20" y="40" id="text1" style="font-family:'Arial Black';font-size:40px;fill:blue;stroke:red">SVG</text>
<text x="20" y="100" id="text2" style="font-family:'Arial Black';font-size:40px;fill:blue;stroke:red">SVG</text>
<text x="20" y="160" id="text3" style="font-family:'Arial Black';font-size:40px;fill:blue;stroke:red">SVG</text>
<text x="20" y="220" id="text4" style="font-family:'Arial Black';font-size:40px;fill:blue;stroke:red">SVG</text>
Copyright © verlag moderne industrie GmbH 2001
You may print the online version for your private use.
Otherwise, this chapter from “Das Einsteigerseminar SVG — Webgrafiken mit XML” is subject to the same conditions as the bound edition. The work, including all its parts, is protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
verlag moderne industrie GmbH, Justus-von-Liebig-Straße 1, D-86899 Landsberg/Lech, fon ++49 (0) 81 91 / 125 – 0, leserservice(at)mi-verlag.de
back to top