XML technologies / SVG / Filters, transformations and gradients / Defining and assigning gradients / Defining a radial gradient
(Excerpt from “Das Einsteigerseminar SVG — Webgrafiken mit XML” by Helma Spona)
Different gradient types use different tags. Enclose their definitions in a <defs> tag at the document’s beginning, as the SVG standard recommends.
For a radial gradient, use the <radialGradient> tag. Name it with the id attribute so you can assign it to an object. The attributes cx, cy and r define the gradient’s structure. cx and cy set its position within the object. The parameters fx and fy set its center, the 0% position. Absolute or percentage values are allowed; the example uses percentages to position the center relative to the object’s size. The attribute r sets the gradient’s radius.
Inside this tag, use the <stop> tag to specify color and position. The gradient’s center is at 0% and its beginning at 100%. For a red-to-white gradient, set red at 100% and white at 0%. Define intermediate colors if needed; otherwise the two blend evenly.
The <stop> tag has these attributes for properties at each position:
offsetsets position as a percentage, for exampleoffset="0%".styledefines formatting. Usestop-colorto specify the color at that position andstop-opacityto set opacity. Values range from0(fully transparent) to1(fully opaque).
The instruction
<stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/>sets the gradient’s center to white with 100% opacity.
<?xml version="1.0" standalone="no"?>
...
<svg width="500" height="500">
<radialGradient id="runderVerlauf" cx="50%" cy="90%" r="60%" fx="60%" fy="80%">
<stop offset="0%" style="stop-color:rgb(255,150,150);stop-opacity:1"/>
<stop offset="1%" style="stop-color:rgb(255,128,128);stop-opacity:1"/>
<stop offset="50%" style="stop-color:rgb(255,0,0);stop-opacity:1"/>
</radialGradient>
</svg>
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