diff --git a/.Rbuildignore b/.Rbuildignore
index ddcf9c2..8109830 100644
--- a/.Rbuildignore
+++ b/.Rbuildignore
@@ -1,5 +1,5 @@
^LICENSE\.md$
-^LEGOMosaics\.Rproj$
+^brickr\.Rproj$
^\.Rproj\.user$
admin_color_tools
^_pkgdown\.yml$
@@ -7,3 +7,6 @@ admin_color_tools
^pkgdown$
^doc$
^Meta$
+^\.travis\.yml$
+^README_files$
+^README\.Rmd$
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..eba8c65
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,4 @@
+# R for travis: see documentation at https://docs.travis-ci.com/user/languages/r
+
+language: R
+cache: packages
diff --git a/DESCRIPTION b/DESCRIPTION
index a88e2c1..fd94ee5 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -1,6 +1,6 @@
Package: brickr
Title: Tools to emulate the LEGO® System in R
-Version: 0.1.0.9014
+Version: 0.1.0.9016
Authors@R:
person(given = "Ryan",
family = "Timpe",
@@ -24,12 +24,17 @@ Imports:
Suggests:
rayshader,
knitr,
- rmarkdown
+ rmarkdown,
+ gridExtra,
+ png,
+ jpeg,
+ tibble
Roxygen: list(markdown = TRUE)
RoxygenNote: 6.1.1
URL: https://github.com/ryantimpe/brickr
BugReports: https://github.com/ryantimpe/brickr/issues
Collate:
+ 'brickr.R'
'bricks-from-mosaic.R'
'bricks-from-rayshader.R'
'bricks-from-tables.R'
diff --git a/Images/goldengirls.JPG b/Images/goldengirls.JPG
deleted file mode 100644
index 0a24780..0000000
Binary files a/Images/goldengirls.JPG and /dev/null differ
diff --git a/Images/mf_unicorn.PNG b/Images/mf_unicorn.PNG
deleted file mode 100644
index a18f04f..0000000
Binary files a/Images/mf_unicorn.PNG and /dev/null differ
diff --git a/NAMESPACE b/NAMESPACE
index b28e1ff..b2effb7 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -20,4 +20,8 @@ export(geom_brick_rect)
export(image_to_mosaic)
export(scale_fill_brick)
export(theme_brick)
+importFrom(grDevices,col2rgb)
+importFrom(grDevices,rgb)
importFrom(magrittr,"%>%")
+importFrom(purrr,"%||%")
+importFrom(stats,median)
diff --git a/R/brickr.R b/R/brickr.R
new file mode 100644
index 0000000..5d69b91
--- /dev/null
+++ b/R/brickr.R
@@ -0,0 +1,22 @@
+#' \code{brickr} package
+#'
+#' Google spreadsheets R API
+#'
+#'
+#' @docType package
+#' @name brickr
+#' @importFrom purrr %||%
+NULL
+
+## quiets concerns of R CMD check re: the .'s that appear in pipelines
+if(getRversion() >= "2.15.1") {
+ utils::globalVariables(c(".", "aes", "alpha", "area_act", "area_tar", "B", "B_lego",
+ "brick_name", "Brick_size", "brick_type", "brickr_themes", "brickrID",
+ "channel", "col2rgb", "Color", "color_hex", "dist", "G", "G_lego",
+ "ggproto", "hex", "lego", "Lego_color", "LEGO_color", "lego_colors",
+ "Lego_name", "Level", "Lum", "n", "offset_x", "offset_y", "Palette",
+ "R", "R_lego", "shade", "shade_bw", "size1", "size2", "stud",
+ "studs", "theme", "Tr", "TYPE", "user_color", "x", "x_mid", "x_scaled",
+ "xg", "xmax", "xmin", "xx", "y", "y_mid", "y_scaled", "yg", "ymax",
+ "ymin", "yy", "z"))
+}
\ No newline at end of file
diff --git a/R/build-instructions.R b/R/build-instructions.R
index f836c6b..294db16 100644
--- a/R/build-instructions.R
+++ b/R/build-instructions.R
@@ -41,7 +41,7 @@ build_instructions <- function(brickr_obj, num_steps=6) {
create_steps <- function(a, n_steps) {
image %>%
- dplyr::filter(between(Level, a-1, a)) %>%
+ dplyr::filter(dplyr::between(Level, a-1, a)) %>%
dplyr::mutate(alpha = ifelse(Level == a, 1, 0.5)) %>%
dplyr::mutate(Step = paste("Step", stringr::str_pad(a, 2, pad = "0")))
diff --git a/R/draw-key.R b/R/draw-key.R
index fad96f4..d1dd3cf 100644
--- a/R/draw-key.R
+++ b/R/draw-key.R
@@ -1,3 +1,4 @@
+#' @importFrom grDevices col2rgb rgb
#' @rdname brickr-ggproto
#' @keywords internal
draw_key_brick <- function(data, params, size) {
diff --git a/R/geom-brick-col.R b/R/geom-brick-col.R
index 5a5cdb1..245e5f2 100644
--- a/R/geom-brick-col.R
+++ b/R/geom-brick-col.R
@@ -25,6 +25,7 @@
#' scale_fill_brick() +
#' coord_brick() +
#' theme_brick()
+#' @importFrom stats median
#' @family Graphs
#' @export
diff --git a/R/image-to-prep-mosaic.R b/R/image-to-prep-mosaic.R
index 51988ec..dcbaad4 100644
--- a/R/image-to-prep-mosaic.R
+++ b/R/image-to-prep-mosaic.R
@@ -80,8 +80,8 @@ image_to_scaled <- function(image, img_size = 48, brightness = 1, warhol = 1:3){
dplyr::mutate(color = rgb(R, G, B)) %>%
dplyr::ungroup() %>%
#Center the image
- dplyr::filter(x <= median(x) + img_size2[1]/2, x > median(x) - img_size2[1]/2,
- y <= median(y) + img_size2[2]/2, y > median(y) - img_size2[2]/2) %>%
+ dplyr::filter(x <= stats::median(x) + img_size2[1]/2, x > stats::median(x) - img_size2[1]/2,
+ y <= stats::median(y) + img_size2[2]/2, y > stats::median(y) - img_size2[2]/2) %>%
#Flip y
dplyr::mutate(y = (max(y) - y) + 1)
diff --git a/R/theme-brick.R b/R/theme-brick.R
index ced1dee..feafc6f 100644
--- a/R/theme-brick.R
+++ b/R/theme-brick.R
@@ -26,11 +26,11 @@ theme_brick <- function(brick_theme = "classic"){
theme_base +
ggplot2::theme(
- # plot.background = element_rect(fill = values$hex[1]),
- panel.background = element_rect(fill = values$hex[1]),
- panel.grid = element_blank(),
- text = element_text(color = values$hex[2]),
- legend.text = element_text(color = values$hex[2], size = 8)
+ # plot.background = ggplot2::element_rect(fill = values$hex[1]),
+ panel.background = ggplot2::element_rect(fill = values$hex[1]),
+ panel.grid = ggplot2::element_blank(),
+ text = ggplot2::element_text(color = values$hex[2]),
+ legend.text = ggplot2::element_text(color = values$hex[2], size = 8)
)
}
\ No newline at end of file
diff --git a/README.Rmd b/README.Rmd
index 377dfd8..24bb4b4 100644
--- a/README.Rmd
+++ b/README.Rmd
@@ -19,6 +19,7 @@ library(tidyverse)
# brickr
[](https://www.tidyverse.org/lifecycle/#experimental)
+ [](https://travis-ci.org/ryantimpe/brickr)
## Overview
@@ -57,7 +58,10 @@ install.packages("rayshader")
The mosaic functions renders an imported JPG or PNG file using LEGO colors and bricks.
```{r m1_set, fig.width = 3, fig.height=3, echo = TRUE, message = FALSE, warning = FALSE}
-mosaic1 <- png::readPNG("Images/mf_unicorn.PNG") %>%
+demo_img = tempfile()
+download.file("http://ryantimpe.com/files/mf_unicorn.PNG", demo_img, mode="wb")
+
+mosaic1 <- png::readPNG(demo_img) %>%
image_to_mosaic(img_size = 36) #Length of each side of mosaic in "bricks"
#Plot 2D mosaic
diff --git a/README.md b/README.md
index ae71442..c6bb118 100644
--- a/README.md
+++ b/README.md
@@ -7,6 +7,8 @@ The LEGO® System in R
[](https://www.tidyverse.org/lifecycle/#experimental)
+[](https://travis-ci.org/ryantimpe/brickr)
## Overview
diff --git a/README_files/figure-gfm/bricks_5-1.png b/README_files/figure-gfm/bricks_5-1.png
index 9804b43..c721ddf 100644
Binary files a/README_files/figure-gfm/bricks_5-1.png and b/README_files/figure-gfm/bricks_5-1.png differ
diff --git a/README_files/figure-gfm/bricks_6-1.png b/README_files/figure-gfm/bricks_6-1.png
index 7bdd8f8..60e3580 100644
Binary files a/README_files/figure-gfm/bricks_6-1.png and b/README_files/figure-gfm/bricks_6-1.png differ
diff --git a/README_files/figure-gfm/geom_brick-1.png b/README_files/figure-gfm/geom_brick-1.png
index 61103ae..bf6e9a3 100644
Binary files a/README_files/figure-gfm/geom_brick-1.png and b/README_files/figure-gfm/geom_brick-1.png differ
diff --git a/README_files/figure-gfm/geom_brick2-1.png b/README_files/figure-gfm/geom_brick2-1.png
index 71c8df2..203248d 100644
Binary files a/README_files/figure-gfm/geom_brick2-1.png and b/README_files/figure-gfm/geom_brick2-1.png differ
diff --git a/README_files/figure-gfm/m1_instructions-1.png b/README_files/figure-gfm/m1_instructions-1.png
index 28ec7ff..a062b18 100644
Binary files a/README_files/figure-gfm/m1_instructions-1.png and b/README_files/figure-gfm/m1_instructions-1.png differ
diff --git a/README_files/figure-gfm/m1_pieces-1.png b/README_files/figure-gfm/m1_pieces-1.png
index cb5fd2f..6353f97 100644
Binary files a/README_files/figure-gfm/m1_pieces-1.png and b/README_files/figure-gfm/m1_pieces-1.png differ
diff --git a/_pkgdown.yml b/_pkgdown.yml
index 0cb5cda..e88139e 100644
--- a/_pkgdown.yml
+++ b/_pkgdown.yml
@@ -27,3 +27,19 @@ reference:
- build_instructions
- starts_with("build_pieces")
- build_themes
+
+articles:
+- title: Mosaics
+ desc: Creating mosaics from images.
+ contents:
+ - '`mosaics`'
+- title: 3D Models
+ desc: Creating 3D LEGO models.
+ contents:
+ - '`models-from-other`'
+ - '`models-from-program`'
+ - '`models-from-tables`'
+- title: Charts
+ desc: ggplot2 brickr extension
+ contents:
+ - '`graphs`'
diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html
index 3ad2e03..871c765 100644
--- a/docs/LICENSE-text.html
+++ b/docs/LICENSE-text.html
@@ -70,7 +70,7 @@
diff --git a/docs/LICENSE.html b/docs/LICENSE.html
index dc895ad..444befa 100644
--- a/docs/LICENSE.html
+++ b/docs/LICENSE.html
@@ -70,7 +70,7 @@
diff --git a/docs/articles/graphs.html b/docs/articles/graphs.html
index 1a68f5e..924a31b 100644
--- a/docs/articles/graphs.html
+++ b/docs/articles/graphs.html
@@ -37,7 +37,7 @@
diff --git a/docs/articles/graphs_files/figure-html/coord-1.png b/docs/articles/graphs_files/figure-html/coord-1.png
index 64567e1..fcea2ee 100644
Binary files a/docs/articles/graphs_files/figure-html/coord-1.png and b/docs/articles/graphs_files/figure-html/coord-1.png differ
diff --git a/docs/articles/graphs_files/figure-html/geom_brick-1.png b/docs/articles/graphs_files/figure-html/geom_brick-1.png
index 194871a..9729fbf 100644
Binary files a/docs/articles/graphs_files/figure-html/geom_brick-1.png and b/docs/articles/graphs_files/figure-html/geom_brick-1.png differ
diff --git a/docs/articles/graphs_files/figure-html/scales-1.png b/docs/articles/graphs_files/figure-html/scales-1.png
index 245bd1a..f7d5fb0 100644
Binary files a/docs/articles/graphs_files/figure-html/scales-1.png and b/docs/articles/graphs_files/figure-html/scales-1.png differ
diff --git a/docs/articles/graphs_files/figure-html/scales2-1.png b/docs/articles/graphs_files/figure-html/scales2-1.png
index eb0ccb6..6dc8b88 100644
Binary files a/docs/articles/graphs_files/figure-html/scales2-1.png and b/docs/articles/graphs_files/figure-html/scales2-1.png differ
diff --git a/docs/articles/index.html b/docs/articles/index.html
index f57dc02..3673ba5 100644
--- a/docs/articles/index.html
+++ b/docs/articles/index.html
@@ -70,7 +70,7 @@
@@ -137,15 +137,29 @@
Creating 3D LEGO models.
+highest_el specifies if ‘light’ or ‘dark’ color bricks should be the tallest in the model. The default is ‘light’.mosaic <- png::readPNG("../Images/mf_unicorn.PNG") %>%
- image_to_mosaic()
+demo_img = tempfile()
+download.file("http://ryantimpe.com/files/mf_unicorn.PNG", demo_img, mode="wb")
-mosaic %>% build_mosaic()
+mosaic <- png::readPNG(demo_img) %>%
+ image_to_mosaic()
+
+mosaic %>% build_mosaic()
mosaic %>%
diff --git a/docs/articles/models-from-program.html b/docs/articles/models-from-program.html
index 5748623..ed4b181 100644
--- a/docs/articles/models-from-program.html
+++ b/docs/articles/models-from-program.html
@@ -37,7 +37,7 @@
You can generate a brickr mosaic object from an image using brickr::image_to_mosaic(). Pass this object to build_mosaic() to construct a visualization of the mosaic.
mosaic <- png::readPNG("../Images/mf_unicorn.PNG") %>%
- image_to_mosaic()
+demo_img = tempfile()
+download.file("http://ryantimpe.com/files/mf_unicorn.PNG", demo_img, mode="wb")
-mosaic %>% build_mosaic()
+mosaic <- png::readPNG(demo_img) %>%
+ image_to_mosaic()
+
+mosaic %>% build_mosaic()
The default is to create a mosaic with 48 knobs (brick studs) on each side. Change this using the img_size input. A single value will create a square mosaic, while an array of two values represent the width and length.
png::readPNG("../Images/mf_unicorn.PNG") %>%
+

@@ -147,11 +150,11 @@
‘special’ colors are typically reserved for certain products and it’s likely that bricks might not be actively produced in these colors.
Use the color_palette input in the image_to_mosaic() function to limit the bricks used to any combination of these three categories.
-p1 <- png::readPNG("../Images/mf_unicorn.PNG") %>%
+p1 <- png::readPNG(demo_img) %>%
image_to_mosaic(32, color_palette = c('universal', 'generic')) %>%
build_mosaic(title = "universal & generic")
-p2 <- png::readPNG("../Images/mf_unicorn.PNG") %>%
+p2 <- png::readPNG(demo_img) %>%
image_to_mosaic(32, color_palette = c('universal')) %>%
build_mosaic(title = "universal")
@@ -162,7 +165,7 @@
Grayscale
For grayscale or black and white mosaics, use color_palette = 'bw'. This creates the mosaic by measuring the brightness of each pixel in the image and mapping it one of the four shades of gray. Use the contrast input to adjust the relative brightness of the pixels.
-png::readPNG("../Images/mf_unicorn.PNG") %>%
+png::readPNG(demo_img) %>%
image_to_mosaic(32, color_palette = 'bw', contrast = 1.1)%>%
build_mosaic()

@@ -175,7 +178,7 @@
lego_colors_wo_blue <- lego_colors %>%
dplyr::filter(!grepl("blue|azur", tolower(Color)))
-png::readPNG("../Images/mf_unicorn.PNG") %>%
+png::readPNG(demo_img) %>%
image_to_mosaic(32, color_table = lego_colors_wo_blue)%>%
build_mosaic(title = "Mosaic without blue or azur")

@@ -187,7 +190,7 @@
brickr uses the farver package to match image colors to the subset of LEGO colors. Technical details of the different algorithms can be found on Wikipedia.
The default algorithm is ‘cie94’, though the other farver options are available using the method input. The farver ‘euclidean’ is not very accurate, so ‘brickr_classic’ returns a manually calculated version for Euclidean RGB distance matching.
c("cie94", "cie2000", "euclidean", "brickr_classic") %>%
- purrr::map(~png::readPNG("../Images/mf_unicorn.PNG") %>%
+ purrr::map(~png::readPNG(demo_img) %>%
image_to_mosaic(24, method =.x) %>%
build_mosaic(title = .x )) -> mosaics_by_method
@@ -198,12 +201,15 @@
Dithering
When rendering a mosaic from a photographic with many shades of similar colors, using dithering by setting dithering = TRUE will help to add texture to the mosaic and avoid large areas of the same color. This works particularly well for large mosaics, but is purely a stylist preference.
-c(FALSE, TRUE) %>%
- purrr::map(~jpeg::readJPEG("../Images/goldengirls.JPG") %>%
- image_to_mosaic(dithering = .x) %>%
- build_mosaic(title = paste("dithering =", .x))) -> mosaics_by_dither
-
-gridExtra::grid.arrange(grobs = mosaics_by_dither, layout_matrix = matrix(c(1,2), ncol=2))
+gg_img = tempfile()
+download.file("http://ryantimpe.com/files/goldengirls.JPG", gg_img, mode="wb")
+
+c(FALSE, TRUE) %>%
+ purrr::map(~jpeg::readJPEG(gg_img) %>%
+ image_to_mosaic(dithering = .x) %>%
+ build_mosaic(title = paste("dithering =", .x))) -> mosaics_by_dither
+
+gridExtra::grid.arrange(grobs = mosaics_by_dither, layout_matrix = matrix(c(1,2), ncol=2))

@@ -216,7 +222,7 @@
3D Mosaics
With rayshader installed, passing the mosaic object to bricks_from_mosaic() will render a 3D object, stacking layers of bricks on each other to create an elevated mosaic. By default, the lightest color bricks will be on top, but this can be changed using the highest_el = 'dark' option.
-png::readPNG("../Images/mf_unicorn.PNG") %>%
+png::readPNG(demo_img) %>%
image_to_mosaic(32) %>%
bricks_from_mosaic(highest_el = "dark") %>%
build_bricks(brick_type = "plate")
diff --git a/docs/authors.html b/docs/authors.html
index 441a9d4..328357e 100644
--- a/docs/authors.html
+++ b/docs/authors.html
@@ -70,7 +70,7 @@
diff --git a/docs/index.html b/docs/index.html
index 6874801..6138b18 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -39,7 +39,7 @@
@@ -150,11 +150,14 @@
Mosaics
The mosaic functions renders an imported JPG or PNG file using LEGO colors and bricks.
-mosaic1 <- png::readPNG("Images/mf_unicorn.PNG") %>%
- image_to_mosaic(img_size = 36) #Length of each side of mosaic in "bricks"
+demo_img = tempfile()
+download.file("http://ryantimpe.com/files/mf_unicorn.PNG", demo_img, mode="wb")
-#Plot 2D mosaic
-mosaic1 %>% build_mosaic()
+mosaic1 <- png::readPNG(demo_img) %>%
+ image_to_mosaic(img_size = 36) #Length of each side of mosaic in "bricks"
+
+#Plot 2D mosaic
+mosaic1 %>% build_mosaic()

In general, any {brickr} function that begins with build_ generates a graphical output from a {brickr} list object from other functions.
diff --git a/docs/index_files/figure-html/geom_brick2-1.png b/docs/index_files/figure-html/geom_brick2-1.png
index 39ab8c5..f75dbb7 100644
Binary files a/docs/index_files/figure-html/geom_brick2-1.png and b/docs/index_files/figure-html/geom_brick2-1.png differ
diff --git a/docs/news/index.html b/docs/news/index.html
index 561133f..a8ec8aa 100644
--- a/docs/news/index.html
+++ b/docs/news/index.html
@@ -70,7 +70,7 @@
diff --git a/docs/reference/brickr-ggproto.html b/docs/reference/brickr-ggproto.html
index 8e5780a..7dc0187 100644
--- a/docs/reference/brickr-ggproto.html
+++ b/docs/reference/brickr-ggproto.html
@@ -72,7 +72,7 @@
diff --git a/docs/reference/brickr.html b/docs/reference/brickr.html
new file mode 100644
index 0000000..befbea6
--- /dev/null
+++ b/docs/reference/brickr.html
@@ -0,0 +1,175 @@
+
+
+
+
+
+
+
+
+brickr package — brickr • brickr
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Google spreadsheets R API
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/docs/reference/bricks_from_coords.html b/docs/reference/bricks_from_coords.html
index 5e5bf10..b9f061d 100644
--- a/docs/reference/bricks_from_coords.html
+++ b/docs/reference/bricks_from_coords.html
@@ -72,7 +72,7 @@