Permalink
Please
sign in to comment.
Showing
with
2,186 additions
and 82 deletions.
- +5 −0 .Rbuildignore
- +1 −0 .gitignore
- +14 −2 DESCRIPTION
- +4 −2 NAMESPACE
- +74 −0 R/collage.R
- +1 −0 R/zzz.R
- +1 −33 README.Rmd
- +3 −45 README.md
- +1 −0 _pkgdown.yml
- +144 −0 docs/404.html
- +146 −0 docs/LICENSE-text.html
- +150 −0 docs/LICENSE.html
- +158 −0 docs/articles/collage.html
- BIN docs/articles/collage_files/figure-html/collage-1.png
- BIN docs/articles/collage_files/figure-html/collage-2.png
- BIN docs/articles/collage_files/figure-html/collage-3.png
- BIN docs/articles/collage_files/figure-html/collage-4.png
- +148 −0 docs/articles/index.html
- +149 −0 docs/authors.html
- +148 −0 docs/docsearch.css
- +85 −0 docs/docsearch.js
- +142 −0 docs/index.html
- +12 −0 docs/link.svg
- +250 −0 docs/pkgdown.css
- +108 −0 docs/pkgdown.js
- +6 −0 docs/pkgdown.yml
- +189 −0 docs/reference/collage.html
- BIN docs/reference/figures/README-pressure-1.png
- +171 −0 docs/reference/index.html
- +24 −0 man/collage.Rd
- BIN man/figures/README-pressure-1.png
- +2 −0 vignettes/.gitignore
- +50 −0 vignettes/collage.Rmd
@@ -1,2 +1,4 @@ | ||
# Generated by roxygen2: fake comment so roxygen2 overwrites silently. | ||
exportPattern("^[^\\.]") | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
export(collage) | ||
importFrom(dplyr,"%>%") |
@@ -0,0 +1,74 @@ | ||
library(ambient) | ||
library(imager) | ||
library(tidyverse) | ||
library(gganimate) | ||
library(purrr) | ||
|
||
#' @importFrom dplyr %>% | ||
NULL | ||
|
||
|
||
#' Creates a collage of noise samples | ||
#' | ||
#' @param generator the function (in ambient) to generate noise | ||
#' @param palette name of a scico palette | ||
#' @param grain how detailed is each panel | ||
#' @param ... arguments to pass to the generator | ||
#' | ||
#' @return A ggplot object | ||
#' @export | ||
collage <- function( | ||
generator = ambient::noise_worley, | ||
palette = "tokyo", | ||
grain = 500, | ||
... | ||
) { | ||
|
||
make_frame <- function(generator, grain, fr, ...) { | ||
|
||
noise <- generator(dim = c(grain, grain), ...) %>% | ||
as.matrix() %>% | ||
tibble::as_tibble() | ||
|
||
noise$x <- 1:grain | ||
noise <- noise %>% | ||
tidyr::gather(key = y, value = value, -x) %>% | ||
dplyr::mutate( | ||
y = y %>% | ||
stringr::str_remove("V") %>% | ||
as.numeric(), | ||
fr = fr) | ||
|
||
return(noise) | ||
} | ||
|
||
noise <- purrr::map( | ||
.x = 1:9, | ||
.f = function(f){ | ||
make_frame( | ||
generator = generator, | ||
grain = grain, | ||
fr = f, | ||
... | ||
) | ||
} | ||
) %>% purrr::reduce(dplyr::bind_rows) | ||
|
||
pic <- noise %>% | ||
ggplot2::ggplot(ggplot2::aes(x=x, y=y, colour=value)) + | ||
ggplot2::geom_raster( | ||
ggplot2::aes(fill=value), | ||
interpolate = TRUE, | ||
show.legend = FALSE) + | ||
scico::scale_fill_scico(palette = palette) + | ||
ggplot2::theme_void() + | ||
ggplot2::coord_equal() + | ||
ggplot2::facet_wrap(~fr) + | ||
ggplot2::theme( | ||
strip.background = ggplot2::element_blank(), | ||
strip.text.x = ggplot2::element_blank() | ||
) | ||
|
||
return(pic) | ||
} | ||
|
@@ -0,0 +1 @@ | ||
utils::globalVariables(c("x", "y", "value")) |
@@ -0,0 +1 @@ | ||
destination: docs |
Oops, something went wrong.
0 comments on commit
7a604dd