Skip to contents

shape_star is a drawable defined by a centroid and two radii: its outline alternates n outer vertices (at outer_radius) with n inner vertices (at inner_radius), evenly spaced by angle, giving the familiar n-pointed star shape (e.g. n = 5 a five-pointed star, n = 6 a Star-of-David-like hexagram outline).

shape_stars() is a vectorized version of shape_star(): each argument may be a vector, recycled against the others. The result is a sketch containing one shape_star() per recycled row, rather than a single drawable.

Usage

shape_star(
  x = 0,
  y = 0,
  outer_radius = 1,
  inner_radius = 0.5,
  n = 5L,
  trans = trans_identity(),
  ...
)

shape_stars(
  x = 0,
  y = 0,
  outer_radius = 1,
  inner_radius = 0.5,
  n = 5L,
  trans = trans_identity(),
  ...
)

Arguments

x, y

Centroid coordinates. Default 0.

outer_radius

Outer radius (star tips). Must be non-negative. Default 1.

inner_radius

Inner radius (between tips). Must be non-negative and no greater than outer_radius. Default 0.5.

n

Number of star points. Must be at least 2. Default 5L.

trans

A trans object applied to the shape's computed points. Default trans_identity() (no transform).

...

Arguments passed to style().

Value

A drawable.

For shape_stars(), a sketch.

Details

Like shape_polygon(), points does not repeat its first vertex at the end – there are exactly 2 * n distinct vertices, since grid::polygonGrob() closes the path itself. The first vertex is an outer one at angle 0; use trans_rotate() to reorient the star, the same way shape_polygon()'s own low-n vertices are reoriented.

inner_radius = outer_radius degenerates the star into a regular 2 * n-gon (no points), and inner_radius = 0 collapses every inner vertex onto the centroid, giving a sharp n-pointed "asterisk" outline.

Recycling uses purrr::pmap()'s own vctrs-based rules: any length-1 element is broadcast to the common length; mismatched lengths greater than 1 raise an error.

Examples

draw(shape_star())

draw(shape_star(x = 1, y = 1, outer_radius = 0.5, n = 8, color = "darkred"))

draw(shape_star(n = 6, fill = "goldenrod"))


# a sharper star: inner_radius closer to 0
draw(shape_star(inner_radius = 0.2, fill = "steelblue"))


# rotating a star reorients its tips
draw(shape_star(n = 5, trans = trans_rotate(pi / 2)))


draw(shape_stars(x = 1:3, n = c(4L, 5L, 6L)))

draw(shape_stars(
  x = 0, y = 0, outer_radius = seq(3, 0.5, length.out = 6), n = 5,
  fill = rep(c("grey20", "grey90"), length.out = 6)
))