Skip to contents

shape_ribbon is a drawable polygon that follows a straight line between (x, y) and (xend, yend), with a width that tapers at both ends and varies along its length according to simplex noise.

shape_ribbons() is a vectorized version of shape_ribbon(): each argument may be a vector, recycled against the others via purrr::pmap()'s own vctrs-based rules. The result is a sketch containing one shape_ribbon() per recycled row, rather than a single drawable.

Usage

shape_ribbon(
  x = 0,
  y = 0,
  xend = 1,
  yend = 1,
  width = 0.2,
  n = 100L,
  distortion = noise_field(),
  trans = trans_identity(),
  ...
)

shape_ribbons(
  x = 0,
  y = 0,
  xend = 1,
  yend = 1,
  width = 0.2,
  n = 100L,
  distortion = noise_field(),
  trans = trans_identity(),
  ...
)

Arguments

x, y

Start point. Default 0.

xend, yend

End point. Default 1.

width

Maximum width. Must be non-negative. Default 0.2.

n

Number of points used along the path. Default 100L.

distortion

A noise_field controlling the width modulation. Default noise_field().

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_ribbons(), a sketch.

Details

Any length-1 element is broadcast to the common length; mismatched lengths greater than 1 raise an error. A shared distortion noise_field is automatically recycled across every ribbon; pass a list() of several different noise_fields instead to vary it per ribbon.

Examples

draw(shape_ribbon(x = 0, y = 0, xend = 1, yend = 1, width = 0.3))


# a higher-frequency distortion modulates width more rapidly along the
# ribbon's length, giving a more textured/organic edge
draw(shape_ribbon(
  x = 0, y = 0, xend = 1, yend = 1, width = 0.3,
  distortion = noise_field(frequency = 8, seed = 99)
))


draw(shape_ribbon(
  x = 0, y = 0, xend = 2, yend = 0, width = 0.4,
  fill = fill_gradient(color = c("steelblue", "white"))
))


draw(shape_ribbons(x = 1:3, y = 0, xend = 2:4, yend = 1, width = 0.3))


# a fan of ribbons radiating from the origin
angle <- seq(0, 2 * pi, length.out = 13)[-13]
draw(shape_ribbons(
  x = 0,
  y = 0,
  xend = cos(angle),
  yend = sin(angle),
  width = 0.1
))