d_regular_ngon() is a wrapper around d_polygon()
to create regular polygon shaped paths.
Its vectorized in its x, y, r, n, a, and offset arguments.
Arguments
- x
If
yisNULLwill be coerced byaffiner::as_coord2d(). Else a numeric vector.- y
Either
NULLor a numeric vector.- r
The radius of the regular polygon (where the vertices lay on).
- n
The number of vertices.
- a
The angle of the first vertex (will be coerced by
affiner::degrees()).- ...
Passed to
d_polygon().- offset
If a positive number the distance for outward polygon offsetting. If a negative number the distance for inward polygon offsetting.
- origin_at_bottom, height
If
origin_at_bottomisTRUEtheny(and anyy1andy2) coordinates is transformed byheight - yfor absolute coordinates and-yfor relative coordinates.
Value
A dee() object.
Examples
# A pentagon
d5 <- d_regular_ngon(x = 5, y = 5, r = 4, n = 5)
if (requireNamespace("omsvg", quietly = TRUE) &&
requireNamespace("nanosvgr", quietly = TRUE)) {
plot(d5, height = 10, width = 10,
fill = "magenta", stroke = "black", stroke_width = 4)
}
# A hexagon
d6 <- d_regular_ngon(x = 5, y = 5, r = 4, n = 6, offset = c(0, -1))
if (requireNamespace("omsvg", quietly = TRUE) &&
requireNamespace("nanosvgr", quietly = TRUE)) {
plot(d6, height = 10, width = 10,
attrs = list(fill_rule = "evenodd"),
fill = "magenta", stroke = "black", stroke_width = 4)
}