svg.line
result = svg.line(x1, y1, x2, y2, [fill="none"], [stroke="#000000"], [stroke_width=1], [opacity=1])
Input: x1, y1, x2, y2, fill, stroke, stroke_width, opacity · Output: result
What it is
A straight segment from (x1, y1) to (x2, y2). Note the defaults are inverted relative to the area shapes: a line has no interior to fill, so it defaults to stroked-black and unfilled.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = svg.line(x1, y1, x2, y2, [fill="none"], [stroke="#000000"], [stroke_width=1], [opacity=1]) | x1 —A straight segment from (x1, y1) to (x2, y2).y1 —A straight segment from (x1, y1) to (x2, y2).x2 —A straight segment from (x1, y1) to (x2, y2).y2 —A straight segment from (x1, y1) to (x2, y2).fill optional (default "none")Note the defaults are inverted relative to the area shapes: a line has no interior to fill, so it defaults to stroked-black and unfilled.stroke optional (default "#000000")not documented yetstroke_width optional (default 1)not documented yetopacity optional (default 1)not documented yet | result Record | Returns a Record with fields kind, x1, y1, x2, y2 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