Skip to content

Commit 04c9800

Browse files
committed
add linewidth arg to spiro
1 parent dd51dc9 commit 04c9800

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

R/spiro.R

+10-7
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
#'
33
#' This function generates a generative art ggplot object in a spirograph style.
44
#'
5-
#' @param n_x Number of spirals per row.
6-
#' @param n_y Number of spirals per column.
7-
#' @param d Diameter.
8-
#' @param R Outer radius.
9-
#' @param r Inner radius.
5+
#' @param n_x Number of spirals per row. Default 10.
6+
#' @param n_y Number of spirals per column. Default 10.
7+
#' @param d Diameter. Default 10.
8+
#' @param R Outer radius. Default 4.
9+
#' @param r Inner radius. Default 1.
10+
#' @param linewidth Width on lines. Default 0.5.
1011
#' @param col_palette Vector of colours. Default "white".
1112
#' @param bg_col Background colour. Default "grey20".
1213
#' @param s Seed value. Default 1234.
@@ -18,12 +19,13 @@ spiro <- function(n_x = 10,
1819
d = 10,
1920
R = 4, # nolint
2021
r = 1,
22+
linewidth = 0.5,
2123
col_palette = "white",
2224
bg_col = "grey20",
2325
s = 1234) {
2426
set.seed(s)
2527
plot_data <- tibble::as_tibble(expand.grid(x = 1:n_x, y = 1:n_y)) |>
26-
dplyr::mutate(dplyr::across(c(.data$x, .data$y), ~ .x * d))
28+
dplyr::mutate(dplyr::across(c("x", "y"), ~ .x * d))
2729
plot_data$cols <- sample(col_palette, size = nrow(plot_data), replace = TRUE)
2830
p <- ggplot2::ggplot(data = plot_data) +
2931
ggforce::geom_spiro(ggplot2::aes(
@@ -34,7 +36,8 @@ spiro <- function(n_x = 10,
3436
y0 = .data$y,
3537
colour = .data$cols,
3638
outer = TRUE
37-
)) +
39+
),
40+
size = linewidth) +
3841
ggplot2::scale_colour_identity() +
3942
ggplot2::coord_fixed() +
4043
ggplot2::theme_void() +

man/spiro.Rd

+8-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)