polygon
polygon(xs, ys)
Input: xs, ys · Output: no output
What it is
Draws a closed shape connecting the points (xs[i], ys[i]) in order and back to the first. xs and ys are equal-length Vecs of numbers (data units).
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
polygon(xs, ys) | xs Vec or numberxs and ys are equal-length Vecs of numbers (data units).ys —Draws a closed shape connecting the points (xs[i], ys[i]) in order and back to the first. | no output | — |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
figure()
polygon([0.0, 1.0, 1.0], [0.0, 0.0, 1.0], fill = "#ff0000")
savefig(tmp_svg)
print(contains(read_all_text(tmp_svg), "opacity=\"0.18\"")) # true
from agent-guide
figure()
polygon([0.0, 1.0, 1.0], [0.0, 0.0, 1.0], fill = "#00ff00", alpha = 1.0)
figure_size(200, 150, unit = "mm")
polygon([2.0, 3.0, 3.0], [0.0, 0.0, 1.0], fill = "#0000ff", alpha = 1.0)
savefig(tmp_svg)
print(regex_count(read_all_text(tmp_svg), "<polygon")) # 2, not 1
from agent-guide
# A square canvas, so that equal ranges really are equal scales and the
# circle below comes out round. Without it the figure would render an
# ellipse while the paragraph above it explained how to avoid one.
figure_size(560, 560)
xlim(-2, 2)
ylim(-2, 2)
axis equal
circle(0, 0, 1, color = "royalblue", fill = "royalblue")
ellipse(0, 0, 1.6, 0.7, color = "crimson", rotate = 30)
arc(0, 0, 1.3, 0, 120, color = "seagreen", width = 2)
polygon([0.8, 1.6, 1.2], [-1.6, -1.6, -0.9], color = "purple", fill = "plum")
rectangle(-1.8, -1.8, -1.2, -1.2, color = "orange")
rect(1.0, -1.8, 1.8, -1.2, color = "teal")
point(0, 1.9)
from plotting
How it works
polygon(xs, ys) — a closed shape through the given points. Two vectors rather than a list of pairs, because that is how every other drawing call here takes coordinates and how the data usually arrives.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.