svg.rect
result = svg.rect(x, y, width, height, [fill="#000000"], [stroke="none"], [stroke_width=1], [opacity=1])
Input: x, y, width, height, fill, stroke, stroke_width, opacity · Output: result
What it is
An axis-aligned rectangle with its top-left corner at (x, y). All four positional arguments are finite numbers; width/height must be 0 or more. fill/stroke are color strings ("#e74c3c", "red", or "none") — a number is refused, because fill="3" is an invalid paint that every renderer silently falls back to black on.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = svg.rect(x, y, width, height, [fill="#000000"], [stroke="none"], [stroke_width=1], [opacity=1]) | x —An axis-aligned rectangle with its top-left corner at (x, y).y —An axis-aligned rectangle with its top-left corner at (x, y).width —width/height must be 0 or more.height —width/height must be 0 or more.fill string or number, optional (default "#000000")fill/stroke are color strings ("#e74c3c", "red", or "none") — a number is refused, because fill="3" is an invalid paint that every renderer silently falls back to black on.stroke string or number, optional (default "none")fill/stroke are color strings ("#e74c3c", "red", or "none") — a number is refused, because fill="3" is an invalid paint that every renderer silently falls back to black on.stroke_width Record, optional (default 1)Returns a Record with fields kind, x, y, width, height, fill, stroke, stroke_width, opacity.opacity Record, optional (default 1)Returns a Record with fields kind, x, y, width, height, fill, stroke, stroke_width, opacity. | result Record | Returns a Record with fields kind, x, y, width, height, fill, stroke, stroke_width, opacity. 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