Qu

svg.path

Builtin index · Images

result = svg.path(d, [fill="none"], [stroke="#000000"], [stroke_width=1], [opacity=1])

Input: d, fill, stroke, stroke_width, opacity · Output: result

What it is

An arbitrary path from the SVG path-data string d. Supports M/L (moveto/lineto), H/V (axis forms), C/Q (cubic and quadratic Bezier) and Z (closepath), each in both absolute (uppercase) and relative (lowercase) spelling, with the SVG repetition rule — a repeated moveto's extra coordinate pairs are implicit linetos. Arcs (A) and the smooth-curve shorthands (S/T) are refused by name rather than passed through, since an unvalidated d produces a file that opens without complaint and draws nothing. d is re-emitted normalized to single-space separation.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = svg.path(d, [fill="none"], [stroke="#000000"], [stroke_width=1], [opacity=1])
d —d is re-emitted normalized to single-space separation.
fill optional (default "none")not documented yet
stroke optional (default "#000000")not documented yet
stroke_width optional (default 1)not documented yet
opacity optional (default 1)not documented yet
result Record
Returns a Record with fields kind, d and the four styling fields. Added in v0.3.0.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

import svg

shapes = [
  svg.rect(10, 10, 100, 50, fill = "#e74c3c"),
  svg.circle(200, 60, 40, fill = "#3498db", stroke = "#000000", stroke_width = 2),
  svg.line(0, 0, 300, 120, stroke = "#333333", stroke_width = 1.5),
  svg.path("M 10 100 L 60 40 L 110 100 Z", stroke = "#2ecc71", stroke_width = 2),
  svg.text(20, 150, "R&D output", font_size = 16, fill = "#111111")]

save_svg("drawing.svg", shapes, width = 320, height = 180)

doc = load_svg("drawing.svg")
print(doc.width)             # 320

print(len(doc.shapes))       # 5

print(doc.shapes[1].kind)    # circle

print(doc.shapes[1].r)       # 40

output
320
5
circle
40

from images