XML technologies / SVG / Using complex graphic elements and formatting / Creating lines, triangles and freehand objects / Drawing more complex objects

(Excerpt from “Das Einsteigerseminar SVG — Webgrafiken mit XML” by Helma Spona)

Combine different path instructions to draw more complex elements. Here we create a small stylized crown, shown below.

Crown drawing to create

Figure: Crown drawing to create.

All you need is a series of L instructions and a closing curve. Create the dots separately with <circle> tags.

<?xml version="1.0" standalone="no"?>
...
<svg width="500" height="500">
  <g transform="translate(70,70)">
    <path style="stroke:rgb(0,0,0);fill:none;stroke-width:2" d="M0 15 l0 -15 l-10 -30 l+20 +30 l+10 -40 l+10 +40 l+20 -30 l-10 +30 l0 +15 a30 10 0 0 0 -40 0"/>
    <circle cx="-20" cy="-40" r="3" />
    <circle cx="20" cy="-50" r="3" />
    <circle cx="56" cy="-40" r="3" />
  </g>
</svg>

The path uses commands in sequence. After setting the starting position, use the line instruction for the straight lines, then an A command for the final curved line. The next figure shows the command order in the <path> tag.

Building the crown’s path from individual instructions

Figure: Building the crown’s path from individual instructions.

The A command also accepts relative coordinates, as the example shows. Use “a” instead of “A”, optionally signing coordinate values. Ellipse radii and rotation values, however, are always absolute, since they do not refer to a position.

Note:
Group the crown and dots with a <g> tag and position them freely. This works because only relative coordinates were used.

Formatting paths

Paths accept the same formatting as other tags: fill colors, gradients, lighting and shadow effects.

Note:
Defining and using lighting, shadows and gradients is explained in Filters, transformations and gradients.

   

 

 

 

back to top