Skip to content

Commit

Permalink
add linewidth arg to spiro
Browse files Browse the repository at this point in the history
  • Loading branch information
nrennie committed Apr 16, 2023
1 parent dd51dc9 commit 04c9800
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
17 changes: 10 additions & 7 deletions R/spiro.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
#'
#' This function generates a generative art ggplot object in a spirograph style.
#'
#' @param n_x Number of spirals per row.
#' @param n_y Number of spirals per column.
#' @param d Diameter.
#' @param R Outer radius.
#' @param r Inner radius.
#' @param n_x Number of spirals per row. Default 10.
#' @param n_y Number of spirals per column. Default 10.
#' @param d Diameter. Default 10.
#' @param R Outer radius. Default 4.
#' @param r Inner radius. Default 1.
#' @param linewidth Width on lines. Default 0.5.
#' @param col_palette Vector of colours. Default "white".
#' @param bg_col Background colour. Default "grey20".
#' @param s Seed value. Default 1234.
Expand All @@ -18,12 +19,13 @@ spiro <- function(n_x = 10,
d = 10,
R = 4, # nolint
r = 1,
linewidth = 0.5,
col_palette = "white",
bg_col = "grey20",
s = 1234) {
set.seed(s)
plot_data <- tibble::as_tibble(expand.grid(x = 1:n_x, y = 1:n_y)) |>
dplyr::mutate(dplyr::across(c(.data$x, .data$y), ~ .x * d))
dplyr::mutate(dplyr::across(c("x", "y"), ~ .x * d))
plot_data$cols <- sample(col_palette, size = nrow(plot_data), replace = TRUE)
p <- ggplot2::ggplot(data = plot_data) +
ggforce::geom_spiro(ggplot2::aes(
Expand All @@ -34,7 +36,8 @@ spiro <- function(n_x = 10,
y0 = .data$y,
colour = .data$cols,
outer = TRUE
)) +
),
size = linewidth) +
ggplot2::scale_colour_identity() +
ggplot2::coord_fixed() +
ggplot2::theme_void() +
Expand Down
13 changes: 8 additions & 5 deletions man/spiro.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 04c9800

Please sign in to comment.