diff --git a/DESCRIPTION b/DESCRIPTION
index 5dc3406..057edd4 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -1,7 +1,7 @@
Package: gridpattern
Type: Package
Title: 'grid' Pattern Grobs
-Version: 1.2.2
+Version: 1.3.0-1
Authors@R: c(
person("Trevor L.", "Davis", role=c("aut", "cre"), email="trevor.l.davis@gmail.com",
comment = c(ORCID = "0000-0001-6341-4639")),
@@ -27,7 +27,9 @@ Imports:
utils
Suggests:
ambient,
+ aRtsy,
ggplot2 (>= 3.5.0),
+ gtable,
knitr,
magick (>= 2.7.4),
ragg (>= 1.2.0),
diff --git a/NAMESPACE b/NAMESPACE
index ae75e1f..3ed96d1 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -13,6 +13,7 @@ S3method(update_pattern_alpha,list)
export(alphaMaskGrob)
export(clippingPathGrob)
export(grid.pattern)
+export(grid.pattern_aRtsy)
export(grid.pattern_ambient)
export(grid.pattern_circle)
export(grid.pattern_crosshatch)
@@ -33,6 +34,7 @@ export(grid.pattern_wave)
export(grid.pattern_weave)
export(guess_has_R4.1_features)
export(mean_col)
+export(names_aRtsy)
export(names_hex)
export(names_magick)
export(names_magick_intensity)
diff --git a/NEWS.md b/NEWS.md
index b44e1ba..74602e3 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,3 +1,9 @@
+gridpattern v1.3.0 (development)
+================================
+
+* New pattern "aRtsy" with corresponding `grid.pattern_aRtsy()` with
+ patterns powered by the `{aRtsy}` package (#87).
+
gridpattern v1.2.2
==================
@@ -25,7 +31,7 @@ Bug fixes and minor improvements
- "placeimg" and "placeimgbw" ([support officially ended July 2023](https://www.gomasuga.com/placeimg?souce=placeimg))
+ The "dummybw" name now provides a pure black-and-white image (i.e. no grey).
- + Fixes a regression for the "placeholderbw" name where it redirected to the "segal" name instead of "placeholder".
+ + Fixes a regression for the "placeholderbw" name where it redirected to the "seagal" name instead of "placeholder".
gridpattern v1.2.1
==================
diff --git a/R/alphaMaskGrob.R b/R/alphaMaskGrob.R
index 496c90e..d5240e1 100644
--- a/R/alphaMaskGrob.R
+++ b/R/alphaMaskGrob.R
@@ -18,7 +18,7 @@
#' @return A `grid` grob
#' @inheritParams grid::polygonGrob
#' @examples
-#' \donttest{ # Once took more >10s on a CRAN autocheck
+#' \donttest{# May take more than 5 seconds on CRAN servers
#' if (capabilities("png") && require("grid")) {
#' maskee <- patternGrob("circle", gp = gpar(col = "black", fill = "yellow"),
#' spacing = 0.1, density = 0.5)
diff --git a/R/grid-pattern.R b/R/grid-pattern.R
index c01657d..e06a616 100644
--- a/R/grid-pattern.R
+++ b/R/grid-pattern.R
@@ -9,6 +9,8 @@
#' \describe{
#' \item{ambient}{Noise array patterns onto the graphic device powered by the `ambient` package.
#' See [grid.pattern_ambient()] for more information.}
+#' \item{aRtsy}{Patterns powered by the `aRtsy` package.
+#' See [grid.pattern_aRtsy()] for more information.}
#' \item{circle}{Circle geometry patterns.
#' See [grid.pattern_circle()] for more information.}
#' \item{crosshatch}{Crosshatch geometry patterns.
@@ -61,7 +63,7 @@
#' If `draw` is `TRUE` then `grid.pattern()` also draws to the graphic device as a side effect.
#' @examples
#' print(names_pattern)
-#' \donttest{ # Once took more >10s on a CRAN autocheck
+#' \donttest{# May take more than 5 seconds on CRAN servers
#' x_hex <- 0.5 + 0.5 * cos(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6))
#' y_hex <- 0.5 + 0.5 * sin(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6))
#'
@@ -125,7 +127,7 @@ grid.pattern <- function(pattern = "stripe",
#' @rdname grid.pattern
#' @export
-names_pattern <- c("ambient", "circle", "crosshatch", "fill", "gradient", "image",
+names_pattern <- c("ambient", "aRtsy", "circle", "crosshatch", "fill", "gradient", "image",
"magick", "none", "pch", "placeholder", "plasma", "polygon_tiling",
"regular_polygon", "rose", "stripe", "text", "wave", "weave")
@@ -175,7 +177,8 @@ get_pattern_fn <- function(pattern) {
user_geometry_fns <- getOption("ggpattern_geometry_funcs")
user_array_fns <- getOption("ggpattern_array_funcs")
assert_patterns_unique(user_geometry_fns, user_array_fns)
- geometry_fns <- c(list(circle = create_pattern_circle_via_sf,
+ geometry_fns <- c(list(aRtsy = create_pattern_aRtsy,
+ circle = create_pattern_circle_via_sf,
crosshatch = create_pattern_crosshatch_via_sf,
fill = create_pattern_fill,
gradient = create_pattern_gradient,
diff --git a/R/pattern-pattern-aRtsy.R b/R/pattern-pattern-aRtsy.R
new file mode 100644
index 0000000..b15834e
--- /dev/null
+++ b/R/pattern-pattern-aRtsy.R
@@ -0,0 +1,77 @@
+#' Create grob objects for the pattern elements within a boundary
+#'
+#' @param params params/coords for a single element. named list or single row data.frame
+#' @param boundary_df mask for the pattern rendering
+#' @param aspect_ratio a aspect ratio of the plotting area.
+#' @param legend is the pattern being created in the legend? default FALSE.
+#' Use this flag if you want different pattern drawing behviour for the legend.
+#'
+#' @return grid grob objects.
+#' @noRd
+create_pattern_aRtsy <- function(params, boundary_df, aspect_ratio,
+ legend = FALSE) {
+ assert_suggested("aRtsy", "aRtsy")
+ requireNamespace("aRtsy", quietly = TRUE)
+ stopifnot(guess_has_R4.1_features("patterns"))
+ alpha <- ifelse(is.na(params$pattern_alpha), 1, params$pattern_alpha)
+ colors <- update_alpha(params$pattern_fill, alpha)
+ fn_name <- paste0("canvas_", params$pattern_type)
+ fn <- utils::getFromNamespace(fn_name, "aRtsy")
+ args <- list()
+ nformals <- names(formals(fn))
+ if ("color" %in% nformals) { # e.g. `canvas_maze()`
+ args$color <- colors
+ }
+ if ("colors" %in% nformals) { # e.g. most canvas functions
+ args$colors <- colors
+ }
+ pat <- ggplot2pat(do.call(fn, args))
+ gp <- grid::gpar(col = NA_character_, fill = pat)
+ convert_polygon_df_to_polygon_grob(boundary_df, gp = gp)
+}
+
+#' Grobs with patterns powered by the aRtsy package
+#'
+#' `grid.pattern_aRtsy()` draws patterns powered by the `aRtsy` package.
+#' `names_aRtsy()` returns character vector of supported types.
+#'
+#' @param type Name of pattern.
+#' @inheritParams grid.pattern_circle
+#' @param fill Passed to the underlying `aRtsy` function's `color` / `colors` argument.
+#' @param ... Currently ignored
+#' @return A grid grob object invisibly. If `draw` is `TRUE` then also draws to the graphic device as a side effect.
+#' @examples
+#' if (requireNamespace("aRtsy", quietly = TRUE)) {
+#' print(names_aRtsy())
+#' }
+#'
+#' \donttest{# Make take more than 5 seconds on CRAN servers
+#' x_hex <- 0.5 + 0.5 * cos(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6))
+#' y_hex <- 0.5 + 0.5 * sin(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6))
+#' if (requireNamespace("aRtsy", quietly = TRUE) &&
+#' guess_has_R4.1_features("patterns")) {
+#' grid::grid.newpage()
+#' grid.pattern_aRtsy(x_hex, y_hex, type = "forest",
+#' fill = c("black", "white", "grey"))
+#' }
+#' }
+#' @seealso for more information about the `aRtsy` package.
+#' @export
+grid.pattern_aRtsy <- function(x = c(0, 0, 1, 1), y = c(1, 0, 0, 1), id = 1L, ...,
+ type = "strokes",
+ fill = gp$fill %||% "grey80",
+ alpha = gp$alpha %||% NA_real_,
+ default.units = "npc", name = NULL, gp = gpar(), draw = TRUE, vp = NULL) {
+ grid.pattern("aRtsy", x, y, id,
+ type = type, fill = fill, alpha = alpha,
+ default.units = default.units, name = name, gp = gp , draw = draw, vp = vp)
+}
+
+#' @rdname grid.pattern_aRtsy
+#' @export
+names_aRtsy <- function() {
+ assert_suggested("aRtsy", "aRtsy")
+ requireNamespace("aRtsy", quietly = TRUE)
+ fns <- grep("^canvas", getNamespaceExports("aRtsy"), value = TRUE)
+ gsub("^canvas_", "", fns)
+}
diff --git a/R/utils-ggplot2.R b/R/utils-ggplot2.R
index 7fe5965..af6b77d 100644
--- a/R/utils-ggplot2.R
+++ b/R/utils-ggplot2.R
@@ -26,3 +26,15 @@ data_frame <- function(...) {
new_data_frame(list(...))
}
.pt <- 2.845276 # ggplot2 constant
+
+ggplot2pat <- function(gg) {
+ stopifnot(getRversion() >= "4.1.0",
+ requireNamespace("ggplot2", quietly = TRUE),
+ requireNamespace("gtable", quietly = TRUE))
+ gg <- suppressMessages(gg +
+ ggplot2::scale_x_continuous(expand=c(0, 0)) +
+ ggplot2::scale_y_continuous(expand=c(0, 0)))
+ grob <- gtable::gtable_filter(ggplot2::ggplotGrob(gg), "panel")
+ pat <- grid::pattern(grob)
+ pat
+}
diff --git a/R/utils-params.R b/R/utils-params.R
index 06c33b1..07d6672 100644
--- a/R/utils-params.R
+++ b/R/utils-params.R
@@ -103,6 +103,7 @@ convert_params_units <- function(params, units = "bigpts") {
default_pattern_type <- function(pattern) {
switch(pattern,
ambient = "simplex",
+ aRtsy = "strokes",
image = "fit",
placeholder = "bear",
polygon_tiling = "square",
diff --git a/README.Rmd b/README.Rmd
index 787e675..57c96c9 100644
--- a/README.Rmd
+++ b/README.Rmd
@@ -26,27 +26,29 @@ as well as original "pch", "polygon_tiling", "regular_polygon", "rose", "text",
`{gridpattern}` currently provides `{grid}` grob support for the following patterns:
-1. [ambient](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_ambient.html):
+1. [ambient](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_ambient.html):
noise array patterns powered by the [ambient](https://cran.r-project.org/package=ambient) package
-2. [circle](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_circle.html): circle geometry patterns
-3. [crosshatch](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_crosshatch.html): crosshatch geometry patterns
-4. [fill](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_fill.html): simple fill patterns
-5. [gradient](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_gradient.html): gradient array/geometry patterns
-6. [image](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_image.html): image array patterns
-7. [magick](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_magick.html): imagemagick array patterns
-8. [none](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_none.html): draws nothing
-9. [placeholder](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_placeholder.html): placeholder image array patterns
-10. [plasma](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_plasma.html): plasma array patterns
-11. [pch](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_pch.html): plotting character geometry patterns
-12. [polygon_tiling](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_polygon_tiling.html): polygon tiling patterns
-13. [regular_polygon](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_regular_polygon.html): regular polygon geometry patterns
-14. [rose](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_rose.html): rose curve array/geometry patterns
-15. [stripe](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_stripe.html): stripe geometry patterns
-16. [text](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_text.html): text array/geometry patterns
-17. [wave](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_wave.html): wave geometry patterns
-18. [weave](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_weave.html): weave geometry patterns
-19. [custom geometry-based patterns](https://trevorldavis.com/R/gridpattern/dev/articles/developing-patterns.html)
-20. [custom array-based patterns](https://trevorldavis.com/R/gridpattern/dev/articles/developing-patterns.html)
+1. [aRtsy](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_aRtsy.html):
+ patterns powered by the [aRtsy](https://cran.r-project.org/package=aRtsy) package
+1. [circle](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_circle.html): circle geometry patterns
+1. [crosshatch](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_crosshatch.html): crosshatch geometry patterns
+1. [fill](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_fill.html): simple fill patterns
+1. [gradient](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_gradient.html): gradient array/geometry patterns
+1. [image](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_image.html): image array patterns
+1. [magick](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_magick.html): imagemagick array patterns
+1. [none](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_none.html): draws nothing
+1. [placeholder](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_placeholder.html): placeholder image array patterns
+1. [plasma](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_plasma.html): plasma array patterns
+1. [pch](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_pch.html): plotting character geometry patterns
+1. [polygon_tiling](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_polygon_tiling.html): polygon tiling patterns
+1. [regular_polygon](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_regular_polygon.html): regular polygon geometry patterns
+1. [rose](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_rose.html): rose curve array/geometry patterns
+1. [stripe](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_stripe.html): stripe geometry patterns
+1. [text](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_text.html): text array/geometry patterns
+1. [wave](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_wave.html): wave geometry patterns
+1. [weave](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_weave.html): weave geometry patterns
+1. [custom geometry-based patterns](https://trevorldavis.com/R/gridpattern/dev/articles/developing-patterns.html)
+1. [custom array-based patterns](https://trevorldavis.com/R/gridpattern/dev/articles/developing-patterns.html)
## Installation
diff --git a/README.md b/README.md
index 847d06c..598a105 100644
--- a/README.md
+++ b/README.md
@@ -26,27 +26,29 @@ as well as original "pch", "polygon_tiling", "regular_polygon", "rose", "text",
`{gridpattern}` currently provides `{grid}` grob support for the following patterns:
-1. [ambient](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_ambient.html):
+1. [ambient](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_ambient.html):
noise array patterns powered by the [ambient](https://cran.r-project.org/package=ambient) package
-2. [circle](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_circle.html): circle geometry patterns
-3. [crosshatch](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_crosshatch.html): crosshatch geometry patterns
-4. [fill](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_fill.html): simple fill patterns
-5. [gradient](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_gradient.html): gradient array/geometry patterns
-6. [image](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_image.html): image array patterns
-7. [magick](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_magick.html): imagemagick array patterns
-8. [none](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_none.html): draws nothing
-9. [placeholder](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_placeholder.html): placeholder image array patterns
-10. [plasma](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_plasma.html): plasma array patterns
-11. [pch](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_pch.html): plotting character geometry patterns
-12. [polygon_tiling](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_polygon_tiling.html): polygon tiling patterns
-13. [regular_polygon](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_regular_polygon.html): regular polygon geometry patterns
-14. [rose](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_rose.html): rose curve array/geometry patterns
-15. [stripe](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_stripe.html): stripe geometry patterns
-16. [text](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_text.html): text array/geometry patterns
-17. [wave](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_wave.html): wave geometry patterns
-18. [weave](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_weave.html): weave geometry patterns
-19. [custom geometry-based patterns](https://trevorldavis.com/R/gridpattern/dev/articles/developing-patterns.html)
-20. [custom array-based patterns](https://trevorldavis.com/R/gridpattern/dev/articles/developing-patterns.html)
+1. [aRtsy](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_aRtsy.html):
+ patterns powered by the [aRtsy](https://cran.r-project.org/package=aRtsy) package
+1. [circle](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_circle.html): circle geometry patterns
+1. [crosshatch](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_crosshatch.html): crosshatch geometry patterns
+1. [fill](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_fill.html): simple fill patterns
+1. [gradient](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_gradient.html): gradient array/geometry patterns
+1. [image](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_image.html): image array patterns
+1. [magick](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_magick.html): imagemagick array patterns
+1. [none](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_none.html): draws nothing
+1. [placeholder](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_placeholder.html): placeholder image array patterns
+1. [plasma](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_plasma.html): plasma array patterns
+1. [pch](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_pch.html): plotting character geometry patterns
+1. [polygon_tiling](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_polygon_tiling.html): polygon tiling patterns
+1. [regular_polygon](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_regular_polygon.html): regular polygon geometry patterns
+1. [rose](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_rose.html): rose curve array/geometry patterns
+1. [stripe](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_stripe.html): stripe geometry patterns
+1. [text](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_text.html): text array/geometry patterns
+1. [wave](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_wave.html): wave geometry patterns
+1. [weave](https://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern_weave.html): weave geometry patterns
+1. [custom geometry-based patterns](https://trevorldavis.com/R/gridpattern/dev/articles/developing-patterns.html)
+1. [custom array-based patterns](https://trevorldavis.com/R/gridpattern/dev/articles/developing-patterns.html)
## Installation
@@ -54,7 +56,7 @@ To install the development version use the following command in R:
-```r
+``` r
remotes::install_github("trevorld/gridpattern")
```
@@ -63,7 +65,7 @@ remotes::install_github("trevorld/gridpattern")
-```r
+``` r
library("grid")
library("gridpattern")
x_hex <- 0.5 + 0.5 * cos(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6))
@@ -71,14 +73,14 @@ y_hex <- 0.5 + 0.5 * sin(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6))
```
-```r
+``` r
grid.pattern_circle(x_hex, y_hex, density = 0.5, grid = "hex_circle",
fill = c("blue", "yellow", "red"))
```
![](man/figures/README-circle-1.png)
-```r
+``` r
grid.pattern_regular_polygon(x_hex, y_hex, shape = c("convex4", "star8", "circle"),
colour = "black", fill = c("blue", "yellow", "red"),
density = c(0.45, 0.42, 0.4), spacing = 0.08, angle = 0)
@@ -86,7 +88,7 @@ grid.pattern_regular_polygon(x_hex, y_hex, shape = c("convex4", "star8", "circle
![](man/figures/README-regular_star-1.png)
-```r
+``` r
grid.pattern_regular_polygon(x_hex, y_hex, shape = "convex6", grid = "hex",
color = "transparent", fill = c("white", "grey", "black"),
density = 1.0, spacing = 0.1)
@@ -94,7 +96,7 @@ grid.pattern_regular_polygon(x_hex, y_hex, shape = "convex6", grid = "hex",
![](man/figures/README-regular_hex-1.png)
-```r
+``` r
gp <- gpar(fill = c("yellow", "blue", "red"))
grid.pattern_polygon_tiling(x_hex, y_hex, type = "truncated_hexagonal",
spacing = 0.15, gp = gp)
@@ -102,7 +104,7 @@ grid.pattern_polygon_tiling(x_hex, y_hex, type = "truncated_hexagonal",
![](man/figures/README-truncated_hexagonal-1.png)
-```r
+``` r
blue <- grDevices::rgb(0.35, 0.70, 0.90)
yellow <- grDevices::rgb(0.95, 0.90, 0.25)
red <- grDevices::rgb(0.80, 0.40, 0.00)
@@ -127,7 +129,7 @@ grid.pattern_regular_polygon(shape = "star12", grid = "hex_circle", rot = 15,
![](man/figures/README-rhombitrihexagonal-1.png)
-```r
+``` r
gp <- gpar(fill = c("blue", "red", "yellow", "green"), col = "black")
grid.newpage()
grid.pattern_rose(x_hex, y_hex,
@@ -137,7 +139,7 @@ grid.pattern_rose(x_hex, y_hex,
![](man/figures/README-rose-1.png)
-```r
+``` r
playing_card_symbols <- c("\u2660", "\u2665", "\u2666", "\u2663")
grid.pattern_text(x_hex, y_hex,
shape = playing_card_symbols,
@@ -147,7 +149,7 @@ grid.pattern_text(x_hex, y_hex,
![](man/figures/README-text-1.png)
-```r
+``` r
grid.pattern_wave(x_hex, y_hex, colour = "black", type = "sine",
fill = c("red", "blue"), density = 0.4,
spacing = 0.15, angle = 0,
@@ -156,7 +158,7 @@ grid.pattern_wave(x_hex, y_hex, colour = "black", type = "sine",
![](man/figures/README-wave-1.png)
-```r
+``` r
grid.pattern_weave(x_hex, y_hex, type = "satin",
colour = "black", fill = "lightblue", fill2 = "yellow",
density = 0.3)
@@ -170,7 +172,7 @@ grid.pattern_weave(x_hex, y_hex, type = "satin",
Here is an example of using the "stripe" pattern:
-```r
+``` r
library("ggpattern") # remotes::install_github("trevorld/ggpattern")
library("ggplot2", warn.conflicts = FALSE)
library("gridpattern")
@@ -189,7 +191,7 @@ three-color polygon tilings using the ``fill`` colour, the ``pattern_fill`` colo
and their "average" color.
-```r
+``` r
tiling3_pattern <- function(params, boundary_df, aspect_ratio, legend = FALSE) {
args <- as.list(params)
args <- args[grep("^pattern_", names(args))]
@@ -226,7 +228,7 @@ Although use of the ["ggpattern" package](#ggpattern) package is still highly re
[`patternFill()`](https://trevorldavis.com/R/gridpattern/dev/reference/patternFill.html) wraps `grid::pattern()` and [patternGrob()](http://trevorldavis.com/R/gridpattern/dev/reference/grid.pattern.html) and is one way to use `gridpattern` patterns directly with `ggplot2`:
-```r
+``` r
library("ggplot2", warn.conflicts = FALSE)
library("gridpattern")
pal <- grDevices::palette()
@@ -245,7 +247,7 @@ ggplot(df, aes(trt, outcome)) +
[piecepackr](https://github.com/piecepackr/piecepackr) allows the use of [custom grob functions](https://trevorldavis.com/piecepackr/custom-grob-functions.html) to completely customize the appearance of one's game pieces. `{piecepackr}` comes with a variety of convenience functions such as `pp_shape()` to facilitate creating custom game pieces using custom grob functions. Here is an example of creating "patterned" checkers filled with uniform polygon tilings by using ``pp_shape()`` objects' `pattern()` method powered by `{gridpattern}`:
-```r
+``` r
library("grid")
library("gridpattern")
library("piecepackr")
diff --git a/man/alphaMaskGrob.Rd b/man/alphaMaskGrob.Rd
index 3fd6133..fc5729b 100644
--- a/man/alphaMaskGrob.Rd
+++ b/man/alphaMaskGrob.Rd
@@ -50,7 +50,7 @@ A \code{grid} grob
\code{alphaMaskGrob()} masks a grob using another grob to specify the (alpha) mask.
}
\examples{
- \donttest{ # Once took more >10s on a CRAN autocheck
+ \donttest{# May take more than 5 seconds on CRAN servers
if (capabilities("png") && require("grid")) {
maskee <- patternGrob("circle", gp = gpar(col = "black", fill = "yellow"),
spacing = 0.1, density = 0.5)
diff --git a/man/grid.pattern.Rd b/man/grid.pattern.Rd
index 1f090bd..25e1c01 100644
--- a/man/grid.pattern.Rd
+++ b/man/grid.pattern.Rd
@@ -7,7 +7,7 @@
\alias{patternGrob}
\title{Create patterned grobs by pattern name}
\format{
-An object of class \code{character} of length 18.
+An object of class \code{character} of length 19.
}
\usage{
grid.pattern(
@@ -88,6 +88,8 @@ Here is a list of the various patterns supported:
\describe{
\item{ambient}{Noise array patterns onto the graphic device powered by the \code{ambient} package.
See \code{\link[=grid.pattern_ambient]{grid.pattern_ambient()}} for more information.}
+\item{aRtsy}{Patterns powered by the \code{aRtsy} package.
+See \code{\link[=grid.pattern_aRtsy]{grid.pattern_aRtsy()}} for more information.}
\item{circle}{Circle geometry patterns.
See \code{\link[=grid.pattern_circle]{grid.pattern_circle()}} for more information.}
\item{crosshatch}{Crosshatch geometry patterns.
@@ -126,7 +128,7 @@ See \code{\link[=grid.pattern_weave]{grid.pattern_weave()}} for more information
}
\examples{
print(names_pattern)
- \donttest{ # Once took more >10s on a CRAN autocheck
+ \donttest{# May take more than 5 seconds on CRAN servers
x_hex <- 0.5 + 0.5 * cos(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6))
y_hex <- 0.5 + 0.5 * sin(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6))
diff --git a/man/grid.pattern_aRtsy.Rd b/man/grid.pattern_aRtsy.Rd
new file mode 100644
index 0000000..4fafee7
--- /dev/null
+++ b/man/grid.pattern_aRtsy.Rd
@@ -0,0 +1,80 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/pattern-pattern-aRtsy.R
+\name{grid.pattern_aRtsy}
+\alias{grid.pattern_aRtsy}
+\alias{names_aRtsy}
+\title{Grobs with patterns powered by the aRtsy package}
+\usage{
+grid.pattern_aRtsy(
+ x = c(0, 0, 1, 1),
+ y = c(1, 0, 0, 1),
+ id = 1L,
+ ...,
+ type = "strokes",
+ fill = gp$fill \%||\% "grey80",
+ alpha = gp$alpha \%||\% NA_real_,
+ default.units = "npc",
+ name = NULL,
+ gp = gpar(),
+ draw = TRUE,
+ vp = NULL
+)
+
+names_aRtsy()
+}
+\arguments{
+\item{x}{A numeric vector or unit object specifying x-locations of the pattern boundary.}
+
+\item{y}{A numeric vector or unit object specifying y-locations of the pattern boundary.}
+
+\item{id}{A numeric vector used to separate locations in x, y into multiple boundaries.
+All locations within the same \code{id} belong to the same boundary.}
+
+\item{...}{Currently ignored}
+
+\item{type}{Name of pattern.}
+
+\item{fill}{Passed to the underlying \code{aRtsy} function's \code{color} / \code{colors} argument.}
+
+\item{alpha}{Alpha (between 0 and 1) or \code{NA} (default, preserves colors' alpha value).}
+
+\item{default.units}{A string indicating the default units to use if \code{x} or \code{y}
+are only given as numeric vectors.}
+
+\item{name}{ A character identifier. }
+
+\item{gp}{An object of class \code{"gpar"}, typically the output
+ from a call to the function \code{\link[grid]{gpar}}. This is basically
+ a list of graphical parameter settings.}
+
+\item{draw}{A logical value indicating whether graphics output
+ should be produced.}
+
+\item{vp}{A Grid viewport object (or NULL).}
+}
+\value{
+A grid grob object invisibly. If \code{draw} is \code{TRUE} then also draws to the graphic device as a side effect.
+}
+\description{
+\code{grid.pattern_aRtsy()} draws patterns powered by the \code{aRtsy} package.
+\code{names_aRtsy()} returns character vector of supported types.
+}
+\examples{
+if (requireNamespace("aRtsy", quietly = TRUE)) {
+ print(names_aRtsy())
+}
+
+\donttest{# Make take more than 5 seconds on CRAN servers
+x_hex <- 0.5 + 0.5 * cos(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6))
+y_hex <- 0.5 + 0.5 * sin(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6))
+if (requireNamespace("aRtsy", quietly = TRUE) &&
+ guess_has_R4.1_features("patterns")) {
+ grid::grid.newpage()
+ grid.pattern_aRtsy(x_hex, y_hex, type = "forest",
+ fill = c("black", "white", "grey"))
+}
+}
+}
+\seealso{
+\url{https://koenderks.github.io/aRtsy/} for more information about the \code{aRtsy} package.
+}
diff --git a/tests/testthat/test_aRtsy.R b/tests/testthat/test_aRtsy.R
new file mode 100644
index 0000000..254f469
--- /dev/null
+++ b/tests/testthat/test_aRtsy.R
@@ -0,0 +1,23 @@
+test_that("aRtsy patterns works as expected", {
+ skip_on_ci()
+ skip_on_cran()
+ skip_if_not_installed("aRtsy")
+ skip_if_not(getRversion() >= "4.3.0")
+ skip_if_not(isTRUE(all(capabilities(c("cairo", "png")))))
+
+ f <- tempfile(fileext = ".png")
+ png(f, type = "cairo")
+ grid.pattern_aRtsy(type = "maze")
+ dev.off()
+ expect_true(file.size(f) > 0)
+ unlink(f)
+
+ f <- tempfile(fileext = ".png")
+ png(f, type = "cairo")
+ grid.pattern_aRtsy(type = "strokes")
+ dev.off()
+ expect_true(file.size(f) > 0)
+ unlink(f)
+
+ expect_true(length(names_aRtsy()) >= 34L)
+})