2
2
# '
3
3
# ' This function generates a generative art ggplot object in a spirograph style.
4
4
# '
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.
10
11
# ' @param col_palette Vector of colours. Default "white".
11
12
# ' @param bg_col Background colour. Default "grey20".
12
13
# ' @param s Seed value. Default 1234.
@@ -18,12 +19,13 @@ spiro <- function(n_x = 10,
18
19
d = 10 ,
19
20
R = 4 , # nolint
20
21
r = 1 ,
22
+ linewidth = 0.5 ,
21
23
col_palette = " white" ,
22
24
bg_col = " grey20" ,
23
25
s = 1234 ) {
24
26
set.seed(s )
25
27
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 ))
27
29
plot_data $ cols <- sample(col_palette , size = nrow(plot_data ), replace = TRUE )
28
30
p <- ggplot2 :: ggplot(data = plot_data ) +
29
31
ggforce :: geom_spiro(ggplot2 :: aes(
@@ -34,7 +36,8 @@ spiro <- function(n_x = 10,
34
36
y0 = .data $ y ,
35
37
colour = .data $ cols ,
36
38
outer = TRUE
37
- )) +
39
+ ),
40
+ size = linewidth ) +
38
41
ggplot2 :: scale_colour_identity() +
39
42
ggplot2 :: coord_fixed() +
40
43
ggplot2 :: theme_void() +
0 commit comments