Skip to content
Please note that GitHub no longer supports your web browser.

We recommend upgrading to the latest Google Chrome or Firefox.

Learn more
Permalink
Browse files

add cursory collage() article

  • Loading branch information
djnavarro committed Oct 1, 2019
1 parent 66fc591 commit 7a604dda54ff6625dc7e9631dba4990b5ec7403e
@@ -3,3 +3,8 @@
^README\.Rmd$
^legacy$
^LICENSE\.md$
^_pkgdown\.yml$
^docs$
^pkgdown$
^.workbch$
^vignettes/collage\.Rmd$
@@ -3,3 +3,4 @@ legacy
.Rhistory
.RData
.workbch
inst/doc
@@ -7,11 +7,23 @@ Authors@R:
role = c("aut", "cre"),
email = "d.navarro@unsw.edu.au",
comment = c(ORCID = "0000-0001-7648-6578"))
Description: What the package does (one paragraph).
Description: It doesn't do much, really.
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
Imports:
ambient
ambient,
purrr,
dplyr,
scico,
ggplot2,
tidyr,
stringr,
tibble
URL: https://github.com/djnavarro/ambien
BugReports: https://github.com/djnavarro/ambien/issues
RoxygenNote: 6.1.1
Suggests:
knitr,
rmarkdown
VignetteBuilder: knitr
@@ -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"))
@@ -17,43 +17,11 @@ knitr::opts_chunk$set(
<!-- badges: start -->
<!-- badges: end -->

The goal of ambien is to have fun

## Installation

You can install the released version of ambien from [CRAN](https://CRAN.R-project.org) with:

``` r
install.packages("ambien")
```

And the development version from [GitHub](https://github.com/) with:
The goal of ambien is to have fun playing around with the multidimensional noise generators in the ambient package. You can install it from [GitHub](https://github.com/) with:

``` r
# install.packages("devtools")
devtools::install_github("djnavarro/ambien")
```
## Example

This is a basic example which shows you how to solve a common problem:

```{r example}
library(ambien)
## basic example code
```

What is special about using `README.Rmd` instead of just `README.md`? You can include R chunks like so:

```{r cars}
summary(cars)
```

You'll still need to render `README.Rmd` regularly, to keep `README.md` up-to-date.

You can also embed plots, for example:

```{r pressure, echo = FALSE}
plot(pressure)
```

In that case, don't forget to commit and push the resulting figure files, so they display on GitHub!
@@ -7,53 +7,11 @@

<!-- badges: end -->

The goal of ambien is to have fun

## Installation

You can install the released version of ambien from
[CRAN](https://CRAN.R-project.org) with:

``` r
install.packages("ambien")
```

And the development version from [GitHub](https://github.com/) with:
The goal of ambien is to have fun playing around with the
multidimensional noise generators in the ambient package. You can
install it from [GitHub](https://github.com/) with:

``` r
# install.packages("devtools")
devtools::install_github("djnavarro/ambien")
```

## Example

This is a basic example which shows you how to solve a common problem:

``` r
library(ambien)
## basic example code
```

What is special about using `README.Rmd` instead of just `README.md`?
You can include R chunks like so:

``` r
summary(cars)
#> speed dist
#> Min. : 4.0 Min. : 2.00
#> 1st Qu.:12.0 1st Qu.: 26.00
#> Median :15.0 Median : 36.00
#> Mean :15.4 Mean : 42.98
#> 3rd Qu.:19.0 3rd Qu.: 56.00
#> Max. :25.0 Max. :120.00
```

You’ll still need to render `README.Rmd` regularly, to keep `README.md`
up-to-date.

You can also embed plots, for example:

<img src="man/figures/README-pressure-1.png" width="100%" />

In that case, don’t forget to commit and push the resulting figure
files, so they display on GitHub\!
@@ -0,0 +1 @@
destination: docs

Some generated files are not rendered by default. Learn more.

0 comments on commit 7a604dd

Please sign in to comment.
You can’t perform that action at this time.