XML technologies / SVG / Using complex graphic elements and formatting / Creating complex elements with Bézier curves / Creating a pattern
(Excerpt from “Das Einsteigerseminar SVG — Webgrafiken mit XML” by Helma Spona)
Attractive Bézier patterns, for example for a webpage banner, generally need a fill. Understand how paths are filled: a closed path, with identical start and end, is filled inside its outline.
An open path is filled as if closed with the z instruction. Curves or wavy lines may produce unwanted results, requiring manual closure to obtain the desired fill.
A simple wavy line would be filled like this:
Figure: A filled Bézier path.
The following steps create a pattern combining Bézier curves and simple transparency, looking like this:
Figure: Target pattern of three paths.
Use three almost identical paths, filled and placed on top of one another.
Note:
Three paths are needed for their different fill colors. Otherwise the three <path> tags could be combined in one <path> tag.
Each path consists of elements using q and t instructions to create a filled S-shape. At the target width, the counterpart returns to the start. The figure shows both.
Figure: Components of the pattern.
The upper element is created by:
<path d="M0 0 q+50 +50 +100 +0 t+100 +0" style="stroke:rgb(0,0,0);stroke-width:1;stroke-opacity:0.5;fill:cyan;fill-opacity:0.5"/>For the lower element, reverse the signs of target X coordinates and control-point X and Y coordinates. The required d attribute is:
d="M200 100 q-50 +50 -100 +0 t-100 +0"Note:
When repeating elements consecutively rather than separately, the lower one needs no start set with the M instruction: it follows from the previous endpoint.
The middle path needs one extra element because it starts earlier and ends later.
<?xml version="1.0" standalone="no"?>
...
<svg width="500" height="500">
<g transform="translate(0,55)">
<path d="M0 0 q+50 +50 +100 +0 t+100 +0 q+50 +50 +100 +0 t+100 +0 q+50 +50 +100 +0 t+100 +0 q-50 +50 -100 +0 t-100 +0 q-50 +50 -100 +0 t-100 +0 q-50 +50 -100 +0 t-100 +0" style="stroke:rgb(0,0,0);stroke-width:1;stroke-opacity:0.5;fill:cyan;fill-opacity:0.5"/>
<path d="M50 -25 q+50 +50 +100 +0 t+100 +0 q+50 +50 +100 +0 t+100 +0 q-50 +50 -100 +0 t-100 +0 q-50 +50 -100 +0 t-100 +0" style="stroke:rgb(0,0,0);stroke-width:1;stroke-opacity:0.5;fill:orange;fill-opacity:0.3"/>
<path d="M50 25 q+50 +50 +100 +0 t+100 +0 q+50 +50 +100 +0 t+100 +0 q-50 +50 -100 +0 t-100 +0 q-50 +50 -100 +0 t-100 +0" style="stroke:rgb(0,0,0);stroke-width:1;stroke-opacity:0.5;fill:yellow;fill-opacity:0.3"/>
</g>
</svg>
Each path’s style attribute controls formatting, including border width and the transparency of borders and fills.
style="stroke:rgb(0,0,0);stroke-width:1;stroke-opacity:0.5;fill:cyan;fill-opacity:0.5"The first path, shown in the middle, sets fill transparency to 50% using fill-opacity:0.5. Border transparency is set to the same value with stroke-opacity:0.5.
Note:
For identical fill and border transparency, omit separate settings and set the whole element’s transparency with opacity:0.5. Applying this to a group produces different results. With fill-opacity:0.5 individual fills show through each other. With opacity:0.5 individual elements are opaque, but the entire group is 50% transparent relative to other elements and groups.
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