I’d like to generate an SVG gradient that varies over time.
In this example code, I’d like to generate an ellipse whose gradient is red with a yellow stripe that travels from west to east over time (creating a shimmer effect):
<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
<defs>
<linearGradient id="grad1" x1="0%" y1="0%" x2="100%" y2="0%">
<stop offset="0%" style="stop-color:rgb(255,0,0);stop-opacity:1" />
<stop offset="0%" style="stop-color:rgb(255,255,0);stop-opacity:1" >
<animate
attributeName="offset"
from="0%"
to="100%"
repeatCount="indefinite"/>
</stop>
<stop offset="100%" style="stop-color:rgb(255,0,0);stop-opacity:1" />
</linearGradient>
</defs>
<ellipse cx="200" cy="70" rx="85" ry="55" fill="url(#grad1)" />
</svg>
This doesn’t work yet, but I’m not sure whether it’s because I’m doing it wrong, or it’s not an effect I can achieve with SVG gradients.
You just need a time period for the animation. Add
dur="5s"for instance as an attribute of theanimateelement.