XML technologies / SVG / Using complex graphic elements and formatting / Creating lines, triangles and freehand objects / Creating a simple line as a path

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

Create paths with the <path> tag. The attribute d supplies path coordinates: any number of coordinate pairs, with additional parameters such as radii or angles for curves.

Each value or pair begins with a special command. The first example draws a simple horizontal line from 100/100 to 200/100, 100 pixels long.

Listing result: a simple line as a path

Figure: Listing result: a simple line as a path.

<?xml version="1.0" standalone="no"?>
...
<svg width="500" height="500">
  <path d="M100 100 L200 100" style="stroke:rgb(0,0,0)"/>
</svg>

The <path> tag, like <rect> and <circle>, has no closing tag and therefore ends with />. The attribute d contains the data, always beginning with the M command, short for Move, setting the starting point. After M, this point is specified by its X and Y coordinates. In the example, M100 100 therefore defines 100/100 as the starting point. From there, paths draw lines or curves. A line is created with the L instruction, followed by the endpoint’s X and Y coordinates, here 200/100. Further line commands are explained later.

Note:
Unlike the other elements used so far, the <path> tag requires the style attribute and a fill or stroke color to make the path visible. Without style, the path is invisible.

   

 

 

 

back to top