From 04c9800dbab32de06dc4858314b771b08fc820de Mon Sep 17 00:00:00 2001 From: nrennie Date: Sun, 16 Apr 2023 12:50:19 +0100 Subject: [PATCH] add linewidth arg to spiro --- R/spiro.R | 17 ++++++++++------- man/spiro.Rd | 13 ++++++++----- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/R/spiro.R b/R/spiro.R index 212ebb8..34fa313 100644 --- a/R/spiro.R +++ b/R/spiro.R @@ -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. @@ -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( @@ -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() + diff --git a/man/spiro.Rd b/man/spiro.Rd index 49ee6de..704c3bf 100644 --- a/man/spiro.Rd +++ b/man/spiro.Rd @@ -10,21 +10,24 @@ spiro( d = 10, R = 4, r = 1, + linewidth = 0.5, col_palette = "white", bg_col = "grey20", s = 1234 ) } \arguments{ -\item{n_x}{Number of spirals per row.} +\item{n_x}{Number of spirals per row. Default 10.} -\item{n_y}{Number of spirals per column.} +\item{n_y}{Number of spirals per column. Default 10.} -\item{d}{Diameter.} +\item{d}{Diameter. Default 10.} -\item{R}{Outer radius.} +\item{R}{Outer radius. Default 4.} -\item{r}{Inner radius.} +\item{r}{Inner radius. Default 1.} + +\item{linewidth}{Width on lines. Default 0.5.} \item{col_palette}{Vector of colours. Default "white".}