Paths, Patterns, and Markers
A line is nice but limited, in that you can only use it to draw from here to there. Polylines and polygons can be used to create more complex images, but not images where the drawing "pen" is moved to a new location in the page without drawing any figure between. The SVG path removes these limitations by providing the ability to draw any number of connected or non-connected points, creating complex lines or even complete images once they're filled in and colored.
Unlike the polygon and polyline functionality discussed in the previous section, a path doesn't take a sequence of points and connect them. Instead, a path takes a sequence of commands and draws the image, or images, based on these commands. The commands are case sensitive, and the type of "lines" drawn change from straight line to curved. Complex drawings generated by drawing tools, like those described later, are invariably created as paths.
Basic Path Commands
Path commands either move the drawing "pen," draw straight lines, or draw curves. They're case sensitive, in that lowercase commands are relative and uppercase are absolute. The basic commands are:
-
M
orm
The moveto command (relative or absolute) moves the digital pen to a new location, beginning a new subpath.
-
L
orl
The lineto command (relative or absolute) draws a line from the current location to the new.
-
Z
orz
Closes the current subpath by drawing a straight line from the current location to the initial starting point.
The path is ...
Get Painting the Web now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.