More vignettes and cleanup

This commit is contained in:
Ryan Timpe
2019-08-18 13:17:10 -04:00
parent 0806223993
commit 515b707cd5
79 changed files with 1516 additions and 209 deletions

View File

@@ -1,6 +1,6 @@
Package: brickr
Title: Tools to emulate the LEGO® System in R
Version: 0.1.0.9012
Version: 0.1.0.9014
Authors@R:
person(given = "Ryan",
family = "Timpe",
@@ -34,6 +34,7 @@ Collate:
'bricks-from-rayshader.R'
'bricks-from-tables.R'
'build-bricks.R'
'build-instructions.R'
'build-mosaic.R'
'collect-bricks.R'
'colors-and-themes.R'

10
NEWS.md
View File

@@ -7,9 +7,7 @@
## Documentation
* pkgdown site
* Vignettes:
- Mosaics
- ggplot extension
* Vignettes
## Mosaics
@@ -27,6 +25,7 @@
* Option to use plates rather than bricks. Combining the two involves some hacking.
* Updated brick collection algorithm to allow for custom brick input.
* Updated brick collection algorithm staggers bricks over layer, though still prioritizes larger bricks.
* `build_instructions` generates building instructions for 3D models, as well as mosaics.
## ggplot Extension
@@ -38,11 +37,8 @@
* ggplot - continuous scale
* 3D model instructions... level by level
* Vignettes
- 3D models from tables
- 3D models from coords
- 3D modesl from mosaics + rayshader
- 3D model from mosaics + rayshader
- IRL
* Website
* Check() breaks at the size check

76
R/build-instructions.R Normal file
View File

@@ -0,0 +1,76 @@
#' Create instruction manual for 2D image mosaics
#'
#' @param brickr_obj brickr mosaic or 3D model object.
#' @param num_steps Number of discrete steps in instruction manual, for mosaics only
#' @family Resources
#' @export
#'
build_instructions <- function(brickr_obj, num_steps=6) {
in_list <- brickr_obj
image <- in_list$Img_bricks
type <- in_list$brickr_object
#Mosaic instructions ----
if(type == "mosaic"){
num_steps <- min(abs(round(num_steps)), 40)
rows_per_step <- ceiling((max(image$ymax)-0.5) / (num_steps+1))
create_steps <- function(a, n_steps) {
if(a < n_steps){
image %>%
dplyr::group_by(brick_name) %>%
dplyr::filter(min(ymin) <= a*rows_per_step+(min(image$ymin)+0.5)) %>%
dplyr::ungroup() %>%
dplyr::mutate(Step = paste("Step", stringr::str_pad(a, 2, pad = "0")))
} else {
image %>%
dplyr::mutate(Step = paste("Step", stringr::str_pad(a, 2, pad = "0")))
}
}
steps_for_plot <- 1:num_steps %>%
purrr::map_df(create_steps, num_steps) %>%
dplyr::mutate(alpha = 1)
} #end mosaics
else if(type == "3dmodel"){
num_steps <- length(unique(image$Level))
create_steps <- function(a, n_steps) {
image %>%
dplyr::filter(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")))
}
steps_for_plot <- 1:num_steps %>%
purrr::map_df(create_steps, num_steps)
}
#Plot ----
coord_ratio <- 1
steps_for_plot %>%
ggplot2::ggplot() +
ggplot2::geom_rect(ggplot2::aes(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
fill = Lego_color, alpha = alpha), color = "#333333") +
ggplot2::scale_fill_identity() +
ggplot2::scale_alpha_identity() +
ggplot2::coord_fixed(ratio = coord_ratio, expand = TRUE) +
ggplot2::facet_wrap(~Step) +
ggplot2::theme_minimal() +
ggplot2::theme( panel.background = ggplot2::element_rect(fill = "#7EC0EE"),
strip.background = ggplot2::element_rect(fill = "#F7F18D"),
strip.text = ggplot2::element_text(color = "#333333", face = "bold"),
axis.line = ggplot2::element_blank(),
axis.title.x = ggplot2::element_blank(),
axis.text.x = ggplot2::element_blank(),
axis.title.y = ggplot2::element_blank(),
axis.text.y = ggplot2::element_blank(),
legend.position = "none")
}

View File

@@ -1,21 +1,19 @@
#' Display 2D LEGO mosaic as a plot image
#'
#' @param image_list List output from collect_bricks() or image_to_bricks(). Contains an element \code{Img_lego}.
#' @param brick_obj List output from image_to_bricks(). Contains an element \code{Img_lego}.
#' @param title Optional title to include above plotted mosaic.
#' @family Mosaics
#' @export
#'
build_mosaic <- function(image_list, title=NULL){
in_list <- image_list
build_mosaic <- function(brick_obj, title=NULL){
in_list <- brick_obj
image <- in_list$Img_bricks
type <- in_list$mosaic_type
coord_x <- c(min(image$xmin)+0.5, max(image$xmax)-0.5)
coord_y <- c(min(image$ymin)+0.5, max(image$ymax)-0.5)
if(type == "stacked") stop("Stacked mosaics have been removed from brickr. Only flat / 'knobs-up' mosaics are supported.")
img <- ggplot2::ggplot(in_list$Img_lego, ggplot2::aes(x=x, y=y)) +
geom_brick_rect(ggplot2::aes(fill = Lego_color), color = "#333333")+
ggplot2::scale_fill_identity() +
@@ -28,56 +26,3 @@ build_mosaic <- function(image_list, title=NULL){
return(img)
}
#' Create instruction manual for 2D image mosaics
#'
#' @param image_list Mosaic object from image_to_mosaic().
#' @param num_steps Number of discrete steps in instruction manual
#' @family Mosaics
#' @export
#'
build_instructions <- function(image_list, num_steps=6) {
in_list <- image_list
image <- in_list$Img_bricks
type <- in_list$mosaic_type
num_steps <- min(abs(round(num_steps)), 40)
rows_per_step <- ceiling((max(image$ymax)-0.5) / (num_steps+1))
create_steps <- function(a, n_steps) {
if(a < n_steps){
image %>%
dplyr::group_by(brick_name) %>%
dplyr::filter(min(ymin) <= a*rows_per_step+(min(image$ymin)+0.5)) %>%
dplyr::ungroup() %>%
dplyr::mutate(Step = paste("Step", (if(a<10){paste0('0', a)}else{a})))
} else {
image %>%
dplyr::mutate(Step = paste("Step", (if(a<10){paste0('0', a)}else{a})))
}
}
#Ratio of the "pixels" is different for flat or stacked bricks
coord_ratio <- 1
1:num_steps %>%
purrr::map(create_steps, num_steps) %>%
dplyr::bind_rows() %>%
ggplot2::ggplot() +
ggplot2::geom_rect(ggplot2::aes(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
fill = Lego_color), color = "#333333") +
ggplot2::scale_fill_identity() +
ggplot2::coord_fixed(ratio = coord_ratio, expand = FALSE) +
ggplot2::facet_wrap(~Step) +
ggplot2::theme_minimal() +
ggplot2::theme( panel.background = ggplot2::element_rect(fill = "#7EC0EE"),
strip.background = ggplot2::element_rect(fill = "#F7F18D"),
strip.text = ggplot2::element_text(color = "#333333", face = "bold"),
axis.line = ggplot2::element_blank(),
axis.title.x = ggplot2::element_blank(),
axis.text.x = ggplot2::element_blank(),
axis.title.y = ggplot2::element_blank(),
axis.text.y = ggplot2::element_blank())
}

View File

@@ -111,7 +111,6 @@ collect_bricks <- function(image_list, use_bricks = NULL){
in_list[["Img_bricks"]] <- img2
in_list[["ID_bricks"]] <- bricks_df
in_list[["mosaic_type"]] <- "flat"
in_list[["pieces"]] <- pcs
return(in_list)

View File

@@ -1,12 +1,12 @@
#' Generate required bricks as a data frame.
#'
#' @param image_list Mosaic output from image_to_mosaic().
#' @param brick_obj brickr mosaic or 3D model object.
#' @return Data frame of piece counts by LEGO color name and size.
#' @family Resources
#' @export
build_pieces_table <- function(image_list){
pcs <- image_list$pieces
build_pieces_table <- function(brick_obj){
pcs <- brick_obj$pieces
pcs %>%
dplyr::select(-Lego_color) %>%
@@ -14,26 +14,25 @@ build_pieces_table <- function(image_list){
dplyr::rename(`LEGO Brick Color` = Lego_name)
}
#' Graphically display required bricks.
#' Display bricks required to build model or mosaic.
#'
#' @param image_list Mosaic output from image_to_mosaic().
#' @param brick_obj brickr mosaic or 3D model object.
#' @return Plot object of required bricks by color and size.
#' @family Resources
#' @export
#'
build_pieces <- function(image_list){
in_list <- image_list
build_pieces <- function(brick_obj){
in_list <- brick_obj
pcs <- in_list$pieces
pcs_coords <- dplyr::tibble(
Brick_size = c("1 x 1", "2 x 1", "3 x 1", "4 x 1", "2 x 2", "4 x 2"),
xmin = c(0, 0, 0, 0, 6, 6),
xmax = c(1, 2, 3, 4, 8, 8),
ymin = c(0, 2, 4, 6, 0, 3),
ymax = c(1, 3, 5, 7, 2, 7)
)
pcs_coords <- dplyr::tibble(
Brick_size = c("1 x 1", "2 x 1", "3 x 1", "4 x 1", "2 x 2", "4 x 2"),
xmin = c(0, 0, 0, 0, 6, 6),
xmax = c(1, 2, 3, 4, 8, 8),
ymin = c(0, 2, 4, 6, 0, 3),
ymax = c(1, 3, 5, 7, 2, 7)
)
#This function creates nodes in each brick for stud placement
pcs_coords <- pcs_coords %>%
@@ -45,33 +44,28 @@ build_pieces <- function(image_list){
pcs2 <- pcs %>%
dplyr::arrange(Lego_color) %>%
dplyr::mutate(Lego_name = factor(Lego_name,
levels = c("Black",
unique(Lego_name)[!(unique(Lego_name) %in% c("Black", "White"))],
"White"))) %>%
levels = c("Black",
unique(Lego_name)[!(unique(Lego_name) %in% c("Black", "White"))],
"White"))) %>%
dplyr::left_join(pcs_coords, by = "Brick_size")
coord_xlim <- c(-0.5, 10)
facet_cols <- 5
coord_xlim <- c(-0.5, 10)
facet_cols <- 5
pcs2 %>%
ggplot2::ggplot() +
ggplot2::geom_rect(ggplot2::aes(xmin=xmin, xmax=xmax, ymin=-ymin, ymax=-ymax,
fill = Lego_color), color = "#333333")+
fill = Lego_color), color = "#333333")+
ggplot2::scale_fill_identity() +
ggplot2::geom_point(data = pcs2 %>% tidyr::unnest(studs),
ggplot2::aes(x=x, y=-y),
color = "#cccccc", alpha = 0.25,
shape = 1, size = 2) +
shape = 1, size = 2) +
ggplot2::geom_text(
ggplot2::aes(x = xmax + 0.25, y = -(ymin+ymax)/2, label = paste0("x", n)),
hjust = 0, vjust = 0.5, size = 3.5) +
ggplot2::aes(x = xmax + 0.25, y = -(ymin+ymax)/2, label = paste0("x", n)),
hjust = 0, vjust = 0.5, size = 3.5) +
ggplot2::coord_fixed(xlim = coord_xlim) +
ggplot2::labs(title = (if(in_list$mosaic_type == "stacked"){
"Suggested LEGO Bricks"
}else{"Suggested LEGO Plates"}),
caption = (if(in_list$mosaic_type == "stacked"){
"Mosaic is 2-bricks deep. Can substitute 2-stud bricks for 1-stud alternatives for a thinner mosaic."}else{""})
) +
ggplot2::labs(title = "Suggested LEGO Bricks") +
ggplot2::facet_wrap(~Lego_name, ncol=facet_cols) +
ggplot2::theme_minimal() +
ggplot2::theme( panel.background = ggplot2::element_rect(fill = "#7EC0EE"),

View File

@@ -174,10 +174,7 @@ sphere_coords %>%
bricks_from_coords() %>%
build_bricks(phi = 30, theta = 30)
rayshader::render_snapshot()
```
```{r, echo=FALSE}
rgl::rgl.clear()
rayshader::render_snapshot(clear = TRUE)
```
### Examples

View File

@@ -136,7 +136,7 @@ brick %>%
bricks_from_table() %>%
build_bricks(brick_res = "uhd")
rayshader::render_snapshot()
rayshader::render_snapshot( clear = TRUE)
```
![](README_files/figure-gfm/bricks_1-1.png)<!-- -->
@@ -185,7 +185,7 @@ my_first_model %>%
bricks_from_table(brick_colors) %>%
build_bricks(theta = 210, brick_res = "hd")
rayshader::render_snapshot()
rayshader::render_snapshot(clear = TRUE)
```
![](README_files/figure-gfm/bricks_5-1.png)<!-- -->
@@ -218,7 +218,7 @@ sphere_coords %>%
bricks_from_coords() %>%
build_bricks(phi = 30, theta = 30)
rayshader::render_snapshot()
rayshader::render_snapshot(clear = TRUE)
```
![](README_files/figure-gfm/bricks_6-1.png)<!-- -->

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

View File

@@ -26,4 +26,4 @@ reference:
- build_colors
- build_instructions
- starts_with("build_pieces")
- build_themes
- build_themes

View File

@@ -70,7 +70,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="index.html">brickr</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9011</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9014</span>
</span>
</div>
@@ -95,6 +95,15 @@
<li>
<a href="articles/graphs.html">ggplot with brickr</a>
</li>
<li>
<a href="articles/models-from-other.html">3D Models from mosaics &amp; rayshader</a>
</li>
<li>
<a href="articles/models-from-program.html">3D Models programmatically</a>
</li>
<li>
<a href="articles/models-from-tables.html">3D models from tables</a>
</li>
<li>
<a href="articles/mosaics.html">Mosaics with brickr</a>
</li>

View File

@@ -70,7 +70,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="index.html">brickr</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9011</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9014</span>
</span>
</div>
@@ -95,6 +95,15 @@
<li>
<a href="articles/graphs.html">ggplot with brickr</a>
</li>
<li>
<a href="articles/models-from-other.html">3D Models from mosaics &amp; rayshader</a>
</li>
<li>
<a href="articles/models-from-program.html">3D Models programmatically</a>
</li>
<li>
<a href="articles/models-from-tables.html">3D models from tables</a>
</li>
<li>
<a href="articles/mosaics.html">Mosaics with brickr</a>
</li>

View File

@@ -37,7 +37,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">brickr</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9011</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9014</span>
</span>
</div>
@@ -62,6 +62,15 @@
<li>
<a href="../articles/graphs.html">ggplot with brickr</a>
</li>
<li>
<a href="../articles/models-from-other.html">3D Models from mosaics &amp; rayshader</a>
</li>
<li>
<a href="../articles/models-from-program.html">3D Models programmatically</a>
</li>
<li>
<a href="../articles/models-from-tables.html">3D models from tables</a>
</li>
<li>
<a href="../articles/mosaics.html">Mosaics with brickr</a>
</li>
@@ -112,7 +121,7 @@
<a class="sourceLine" id="cb1-6" title="6"><span class="st"> </span><span class="kw"><a href="../reference/scale_fill_brick.html">scale_fill_brick</a></span>() <span class="op">+</span></a>
<a class="sourceLine" id="cb1-7" title="7"><span class="st"> </span><span class="kw"><a href="../reference/coord-brick.html">coord_brick</a></span>() <span class="op">+</span></a>
<a class="sourceLine" id="cb1-8" title="8"><span class="st"> </span><span class="kw"><a href="../reference/theme_brick.html">theme_brick</a></span>()</a></code></pre></div>
<p><img src="graphs_files/figure-html/getting_started-1.png" width="384"></p>
<p><img src="../../../../OneDrive%20-%20LEGO/Documents/brickr/docs/articles/graphs_files/figure-html/getting_started-1.png" width="384"></p>
<ul>
<li>
<a href="#geoms"><code><a href="../reference/geom_brick_col.html">geom_brick_col()</a></code></a> draws data columns as bricks.</li>
@@ -155,7 +164,7 @@
<a class="sourceLine" id="cb2-6" title="6"><span class="st"> </span><span class="kw"><a href="../reference/scale_fill_brick.html">scale_fill_brick</a></span>() <span class="op">+</span></a>
<a class="sourceLine" id="cb2-7" title="7"><span class="st"> </span><span class="kw"><a href="../reference/coord-brick.html">coord_brick</a></span>() <span class="op">+</span></a>
<a class="sourceLine" id="cb2-8" title="8"><span class="st"> </span><span class="kw"><a href="../reference/theme_brick.html">theme_brick</a></span>()</a></code></pre></div>
<p><img src="graphs_files/figure-html/geom_brick-1.png" width="480"></p>
<p><img src="../../../../OneDrive%20-%20LEGO/Documents/brickr/docs/articles/graphs_files/figure-html/geom_brick-1.png" width="480"></p>
</div>
</div>
<div id="coords" class="section level2">
@@ -171,7 +180,7 @@
<a class="sourceLine" id="cb3-6" title="6"><span class="st"> </span><span class="kw"><a href="../reference/coord-brick.html">coord_brick_flip</a></span>() <span class="op">+</span></a>
<a class="sourceLine" id="cb3-7" title="7"><span class="st"> </span><span class="kw"><a href="../reference/theme_brick.html">theme_brick</a></span>() <span class="op">+</span></a>
<a class="sourceLine" id="cb3-8" title="8"><span class="st"> </span><span class="kw">theme</span>(<span class="dt">legend.position =</span> <span class="st">"none"</span>)</a></code></pre></div>
<p><img src="graphs_files/figure-html/coord-1.png" width="480"></p>
<p><img src="../../../../OneDrive%20-%20LEGO/Documents/brickr/docs/articles/graphs_files/figure-html/coord-1.png" width="480"></p>
</div>
<div id="scale-and-themes" class="section level2">
<h2 class="hasAnchor">
@@ -191,14 +200,14 @@
<a class="sourceLine" id="cb4-8" title="8"><span class="st"> </span><span class="kw"><a href="../reference/coord-brick.html">coord_brick</a></span>() <span class="op">+</span></a>
<a class="sourceLine" id="cb4-9" title="9"><span class="st"> </span><span class="kw"><a href="../reference/theme_brick.html">theme_brick</a></span>(<span class="dt">brick_theme =</span> use_theme) <span class="op">+</span></a>
<a class="sourceLine" id="cb4-10" title="10"><span class="st"> </span><span class="kw">labs</span>(<span class="dt">title =</span> use_theme)</a></code></pre></div>
<p><img src="graphs_files/figure-html/scales-1.png" width="384"></p>
<p><img src="graphs_files/figure-html/scales2-1.png" width="960"></p>
<p><img src="../../../../OneDrive%20-%20LEGO/Documents/brickr/docs/articles/graphs_files/figure-html/scales-1.png" width="384"></p>
<p><img src="../../../../OneDrive%20-%20LEGO/Documents/brickr/docs/articles/graphs_files/figure-html/scales2-1.png" width="960"></p>
</div>
<div id="themes" class="section level3">
<h3 class="hasAnchor">
<a href="#themes" class="anchor"></a>Themes</h3>
<p>For a complete list of available themes, use <code><a href="../reference/build_themes.html">build_themes()</a></code>.</p>
<p><img src="graphs_files/figure-html/themes-1.png" width="672"></p>
<p><img src="../../../../OneDrive%20-%20LEGO/Documents/brickr/docs/articles/graphs_files/figure-html/themes-1.png" width="672"></p>
</div>
</div>
</div>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 70 KiB

After

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 75 KiB

After

Width:  |  Height:  |  Size: 85 KiB

View File

@@ -70,7 +70,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">brickr</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9011</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9014</span>
</span>
</div>
@@ -95,6 +95,15 @@
<li>
<a href="../articles/graphs.html">ggplot with brickr</a>
</li>
<li>
<a href="../articles/models-from-other.html">3D Models from mosaics &amp; rayshader</a>
</li>
<li>
<a href="../articles/models-from-program.html">3D Models programmatically</a>
</li>
<li>
<a href="../articles/models-from-tables.html">3D models from tables</a>
</li>
<li>
<a href="../articles/mosaics.html">Mosaics with brickr</a>
</li>
@@ -133,6 +142,9 @@
<ul>
<li><a href="graphs.html">ggplot with brickr</a></li>
<li><a href="models-from-other.html">3D Models from mosaics &amp; rayshader</a></li>
<li><a href="models-from-program.html">3D Models programmatically</a></li>
<li><a href="models-from-tables.html">3D models from tables</a></li>
<li><a href="mosaics.html">Mosaics with brickr</a></li>
</ul>
</div>

View File

@@ -0,0 +1,219 @@
<!DOCTYPE html>
<!-- Generated by pkgdown: do not edit by hand --><html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>3D Models from mosaics &amp; rayshader • brickr</title>
<!-- favicons --><link rel="icon" type="image/png" sizes="16x16" href="../favicon-16x16.png">
<link rel="icon" type="image/png" sizes="32x32" href="../favicon-32x32.png">
<link rel="apple-touch-icon" type="image/png" sizes="180x180" href="../apple-touch-icon.png">
<link rel="apple-touch-icon" type="image/png" sizes="120x120" href="../apple-touch-icon-120x120.png">
<link rel="apple-touch-icon" type="image/png" sizes="76x76" href="../apple-touch-icon-76x76.png">
<link rel="apple-touch-icon" type="image/png" sizes="60x60" href="../apple-touch-icon-60x60.png">
<!-- jquery --><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script><!-- Bootstrap --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha256-916EbMg70RQy9LHiGkXzG8hSg9EdNy97GazNG/aiY1w=" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha256-U5ZEeKfGNOja007MMD3YBI0A3OSZOQbeG6z2f2Y0hu8=" crossorigin="anonymous"></script><!-- Font Awesome icons --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" integrity="sha256-eZrrJcwDc/3uDhsdt61sL2oOBY362qM3lon1gyExkL0=" crossorigin="anonymous">
<!-- clipboard.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.4/clipboard.min.js" integrity="sha256-FiZwavyI2V6+EXO1U+xzLG3IKldpiTFf3153ea9zikQ=" crossorigin="anonymous"></script><!-- sticky kit --><script src="https://cdnjs.cloudflare.com/ajax/libs/sticky-kit/1.1.3/sticky-kit.min.js" integrity="sha256-c4Rlo1ZozqTPE2RLuvbusY3+SU1pQaJC0TjuhygMipw=" crossorigin="anonymous"></script><!-- pkgdown --><link href="../pkgdown.css" rel="stylesheet">
<script src="../pkgdown.js"></script><meta property="og:title" content="3D Models from mosaics &amp; rayshader">
<meta property="og:description" content="">
<meta property="og:image" content="http://brickr.org/logo.png">
<meta name="twitter:card" content="summary">
<!-- mathjax --><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script><!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container template-article">
<header><div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">brickr</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9014</span>
</span>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>
<a href="../index.html">
<span class="fa fa-home fa-lg"></span>
</a>
</li>
<li>
<a href="../reference/index.html">Reference</a>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
Articles
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="../articles/graphs.html">ggplot with brickr</a>
</li>
<li>
<a href="../articles/models-from-other.html">3D Models from mosaics &amp; rayshader</a>
</li>
<li>
<a href="../articles/models-from-program.html">3D Models programmatically</a>
</li>
<li>
<a href="../articles/models-from-tables.html">3D models from tables</a>
</li>
<li>
<a href="../articles/mosaics.html">Mosaics with brickr</a>
</li>
</ul>
</li>
<li>
<a href="../news/index.html">Changelog</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>
<a href="https://github.com/ryantimpe/brickr">
<span class="fa fa-github fa-lg"></span>
</a>
</li>
</ul>
</div>
<!--/.nav-collapse -->
</div>
<!--/.container -->
</div>
<!--/.navbar -->
</header><div class="row">
<div class="col-md-9 contents">
<div class="page-header toc-ignore">
<h1>3D Models from mosaics &amp; rayshader</h1>
<small class="dont-index">Source: <a href="https://github.com/ryantimpe/brickr/blob/master/vignettes/models-from-other.Rmd"><code>vignettes/models-from-other.Rmd</code></a></small>
<div class="hidden name"><code>models-from-other.Rmd</code></div>
</div>
<div id="getting-started" class="section level2">
<h2 class="hasAnchor">
<a href="#getting-started" class="anchor"></a>Getting started</h2>
<p>The <code>bricks_from_*</code> series of functions creates 3D models of LEGO bricks from a variety of input formats. These models are rendered using <a href="https://twitter.com/tylermorganwall">Tyler Morgan-Wall</a>s <a href="https://www.rayshader.com/">rayshader</a> package. This package must be installed.</p>
</div>
<div id="d-mosaics" class="section level2">
<h2 class="hasAnchor">
<a href="#d-mosaics" class="anchor"></a>3D mosaics</h2>
<p>Begin with a brickr mosaic from an image. Rather than graphically rendering the mosaic using <code><a href="../reference/build_mosaic.html">build_mosaic()</a></code>, use <code><a href="../reference/bricks_from_mosaic.html">bricks_from_mosaic()</a></code>. This function takes two other inputs:</p>
<ul>
<li>
<code>mosaic_height</code> is the number of bricks stacked at the mosaics highest point. The default is 6.</li>
<li>
<code>highest_el</code> specifies if light or dark color bricks should be the tallest in the model. The default is light.</li>
</ul>
<div class="sourceCode" id="cb1"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb1-1" title="1">mosaic &lt;-<span class="st"> </span>png<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/png/topics/readPNG">readPNG</a></span>(<span class="st">"../Images/mf_unicorn.PNG"</span>) <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb1-2" title="2"><span class="st"> </span><span class="kw"><a href="../reference/image_to_mosaic.html">image_to_mosaic</a></span>()</a>
<a class="sourceLine" id="cb1-3" title="3"></a>
<a class="sourceLine" id="cb1-4" title="4">mosaic <span class="op">%&gt;%</span><span class="st"> </span><span class="kw"><a href="../reference/build_mosaic.html">build_mosaic</a></span>()</a></code></pre></div>
<p><img src="models-from-other_files/figure-html/bricks_6-1.png" width="384"></p>
<div class="sourceCode" id="cb2"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb2-1" title="1"></a>
<a class="sourceLine" id="cb2-2" title="2">mosaic <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb2-3" title="3"><span class="st"> </span><span class="kw"><a href="../reference/bricks_from_mosaic.html">bricks_from_mosaic</a></span>(<span class="dt">highest_el =</span> <span class="st">"dark"</span>) <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb2-4" title="4"><span class="st"> </span><span class="kw"><a href="../reference/build_bricks.html">build_bricks</a></span>(<span class="dt">phi =</span> <span class="dv">60</span>, <span class="dt">theta =</span> <span class="dv">15</span>)</a>
<a class="sourceLine" id="cb2-5" title="5"></a>
<a class="sourceLine" id="cb2-6" title="6">rayshader<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/rayshader/topics/render_snapshot">render_snapshot</a></span>(<span class="dt">clear =</span> <span class="ot">TRUE</span>)</a></code></pre></div>
<p><img src="models-from-other_files/figure-html/bricks_6-2.png" width="384"></p>
</div>
<div id="models-from-rayshader" class="section level2">
<h2 class="hasAnchor">
<a href="#models-from-rayshader" class="anchor"></a>Models from rayshader</h2>
<p><a href="https://www.rayshader.com/">rayshader</a> by <a href="https://twitter.com/tylermorganwall">Tyler Morgan-Wall</a> is an open source package for producing 2D and 3D data visualizations in R. rayshader uses elevation data in a base R matrix and a combination of raytracing, spherical texture mapping, overlays, and ambient occlusion to generate beautiful topographic 2D and 3D maps. (Note: text lifted straight from <a href="https://www.rayshader.com/">rayshader.com</a>.)</p>
<p>3D models in <strong>brickr</strong> are rendered using the functions in <strong>rayshader</strong>. Using <code><a href="../reference/bricks_from_rayshader.html">bricks_from_rayshader()</a></code>, you can convert rayshader map output into a brickr model. This function takes three inputs:</p>
<ul>
<li>
<code>hillshade</code> is topographic image matrix with an RGB channel (much like the mosaics).</li>
<li>
<code>heightmap</code> is a two-dimensional matrix specifiying the height of the image at each location.</li>
<li>
<code>max_height</code> is the number of bricks stacked at the mosaics highest point. The default is 12.</li>
<li>
<code>img_size</code> is the number of bricks on each side of the model. The default is 48.</li>
</ul>
<div class="sourceCode" id="cb3"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb3-1" title="1"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/library">library</a></span>(rayshader)</a>
<a class="sourceLine" id="cb3-2" title="2"></a>
<a class="sourceLine" id="cb3-3" title="3"><span class="co">#Example from rayshader.com</span></a>
<a class="sourceLine" id="cb3-4" title="4"></a>
<a class="sourceLine" id="cb3-5" title="5"><span class="co">#Here, I load a map with the raster package.</span></a>
<a class="sourceLine" id="cb3-6" title="6">loadzip =<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/tempfile">tempfile</a></span>() </a>
<a class="sourceLine" id="cb3-7" title="7"><span class="kw"><a href="https://www.rdocumentation.org/packages/utils/topics/download.file">download.file</a></span>(<span class="st">"https://tylermw.com/data/dem_01.tif.zip"</span>, loadzip)</a>
<a class="sourceLine" id="cb3-8" title="8">localtif =<span class="st"> </span>raster<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/raster/topics/raster">raster</a></span>(<span class="kw"><a href="https://www.rdocumentation.org/packages/utils/topics/unzip">unzip</a></span>(loadzip, <span class="st">"dem_01.tif"</span>))</a>
<a class="sourceLine" id="cb3-9" title="9"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/unlink">unlink</a></span>(loadzip)</a>
<a class="sourceLine" id="cb3-10" title="10"></a>
<a class="sourceLine" id="cb3-11" title="11"><span class="co">#And convert it to a matrix:</span></a>
<a class="sourceLine" id="cb3-12" title="12">elmat =<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/matrix">matrix</a></span>(raster<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/raster/topics/extract">extract</a></span>(localtif, raster<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/raster/topics/extent">extent</a></span>(localtif), <span class="dt">buffer =</span> <span class="dv">1000</span>),</a>
<a class="sourceLine" id="cb3-13" title="13"> <span class="dt">nrow =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/nrow">ncol</a></span>(localtif), <span class="dt">ncol =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/nrow">nrow</a></span>(localtif))</a>
<a class="sourceLine" id="cb3-14" title="14"></a>
<a class="sourceLine" id="cb3-15" title="15">rayshader_object &lt;-<span class="st"> </span>elmat <span class="op">%&gt;%</span></a>
<a class="sourceLine" id="cb3-16" title="16"><span class="st"> </span><span class="kw">sphere_shade</span>(<span class="dt">texture =</span> <span class="st">"desert"</span>) <span class="op">%&gt;%</span></a>
<a class="sourceLine" id="cb3-17" title="17"><span class="st"> </span><span class="kw">add_water</span>(<span class="kw">detect_water</span>(elmat), <span class="dt">color =</span> <span class="st">"desert"</span>) <span class="op">%&gt;%</span></a>
<a class="sourceLine" id="cb3-18" title="18"><span class="st"> </span><span class="kw">add_shadow</span>(<span class="kw">ray_shade</span>(elmat, <span class="dt">zscale =</span> <span class="dv">3</span>, <span class="dt">maxsearch =</span> <span class="dv">300</span>), <span class="fl">0.5</span>) </a>
<a class="sourceLine" id="cb3-19" title="19"></a>
<a class="sourceLine" id="cb3-20" title="20"><span class="co">#Plot with rayshader</span></a>
<a class="sourceLine" id="cb3-21" title="21">rayshader_object <span class="op">%&gt;%</span></a>
<a class="sourceLine" id="cb3-22" title="22"><span class="st"> </span><span class="kw">plot_3d</span>(elmat, <span class="dt">zscale =</span> <span class="dv">10</span>, <span class="dt">fov =</span> <span class="dv">0</span>, <span class="dt">theta =</span> <span class="dv">135</span>, <span class="dt">zoom =</span> <span class="fl">0.75</span>, <span class="dt">phi =</span> <span class="dv">45</span>, <span class="dt">windowsize =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="dv">1000</span>, <span class="dv">800</span>))</a>
<a class="sourceLine" id="cb3-23" title="23"></a>
<a class="sourceLine" id="cb3-24" title="24">rayshader<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/rayshader/topics/render_snapshot">render_snapshot</a></span>(<span class="dt">clear =</span> <span class="ot">TRUE</span>)</a></code></pre></div>
<p><img src="models-from-other_files/figure-html/bricks_rayshader-1.png" width="384"></p>
<div class="sourceCode" id="cb4"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb4-1" title="1"></a>
<a class="sourceLine" id="cb4-2" title="2"><span class="co">#Plot as bricks</span></a>
<a class="sourceLine" id="cb4-3" title="3">rayshader_object <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb4-4" title="4"><span class="st"> </span><span class="kw"><a href="../reference/bricks_from_rayshader.html">bricks_from_rayshader</a></span>(elmat) <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb4-5" title="5"><span class="st"> </span><span class="kw"><a href="../reference/build_bricks.html">build_bricks</a></span>(<span class="dt">theta =</span> <span class="dv">135</span>, <span class="dt">zoom =</span> <span class="fl">0.75</span>, <span class="dt">phi =</span> <span class="dv">45</span>)</a>
<a class="sourceLine" id="cb4-6" title="6"></a>
<a class="sourceLine" id="cb4-7" title="7">rayshader<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/rayshader/topics/render_snapshot">render_snapshot</a></span>(<span class="dt">clear =</span> <span class="ot">TRUE</span>)</a></code></pre></div>
<p><img src="models-from-other_files/figure-html/bricks_rayshader-2.png" width="384"></p>
</div>
</div>
<div class="col-md-3 hidden-xs hidden-sm" id="sidebar">
<div id="tocnav">
<h2 class="hasAnchor">
<a href="#tocnav" class="anchor"></a>Contents</h2>
<ul class="nav nav-pills nav-stacked">
<li><a href="#getting-started">Getting started</a></li>
<li><a href="#d-mosaics">3D mosaics</a></li>
<li><a href="#models-from-rayshader">Models from rayshader</a></li>
</ul>
</div>
</div>
</div>
<footer><div class="copyright">
<p>Developed by Ryan Timpe.</p>
</div>
<div class="pkgdown">
<p>Site built with <a href="https://pkgdown.r-lib.org/">pkgdown</a> 1.3.0.</p>
</div>
</footer>
</div>
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 241 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 337 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 364 KiB

View File

@@ -0,0 +1,260 @@
<!DOCTYPE html>
<!-- Generated by pkgdown: do not edit by hand --><html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>3D Models programmatically • brickr</title>
<!-- favicons --><link rel="icon" type="image/png" sizes="16x16" href="../favicon-16x16.png">
<link rel="icon" type="image/png" sizes="32x32" href="../favicon-32x32.png">
<link rel="apple-touch-icon" type="image/png" sizes="180x180" href="../apple-touch-icon.png">
<link rel="apple-touch-icon" type="image/png" sizes="120x120" href="../apple-touch-icon-120x120.png">
<link rel="apple-touch-icon" type="image/png" sizes="76x76" href="../apple-touch-icon-76x76.png">
<link rel="apple-touch-icon" type="image/png" sizes="60x60" href="../apple-touch-icon-60x60.png">
<!-- jquery --><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script><!-- Bootstrap --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha256-916EbMg70RQy9LHiGkXzG8hSg9EdNy97GazNG/aiY1w=" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha256-U5ZEeKfGNOja007MMD3YBI0A3OSZOQbeG6z2f2Y0hu8=" crossorigin="anonymous"></script><!-- Font Awesome icons --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" integrity="sha256-eZrrJcwDc/3uDhsdt61sL2oOBY362qM3lon1gyExkL0=" crossorigin="anonymous">
<!-- clipboard.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.4/clipboard.min.js" integrity="sha256-FiZwavyI2V6+EXO1U+xzLG3IKldpiTFf3153ea9zikQ=" crossorigin="anonymous"></script><!-- sticky kit --><script src="https://cdnjs.cloudflare.com/ajax/libs/sticky-kit/1.1.3/sticky-kit.min.js" integrity="sha256-c4Rlo1ZozqTPE2RLuvbusY3+SU1pQaJC0TjuhygMipw=" crossorigin="anonymous"></script><!-- pkgdown --><link href="../pkgdown.css" rel="stylesheet">
<script src="../pkgdown.js"></script><meta property="og:title" content="3D Models programmatically">
<meta property="og:description" content="">
<meta property="og:image" content="http://brickr.org/logo.png">
<meta name="twitter:card" content="summary">
<!-- mathjax --><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script><!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container template-article">
<header><div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">brickr</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9014</span>
</span>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>
<a href="../index.html">
<span class="fa fa-home fa-lg"></span>
</a>
</li>
<li>
<a href="../reference/index.html">Reference</a>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
Articles
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="../articles/graphs.html">ggplot with brickr</a>
</li>
<li>
<a href="../articles/models-from-other.html">3D Models from mosaics &amp; rayshader</a>
</li>
<li>
<a href="../articles/models-from-program.html">3D Models programmatically</a>
</li>
<li>
<a href="../articles/models-from-tables.html">3D models from tables</a>
</li>
<li>
<a href="../articles/mosaics.html">Mosaics with brickr</a>
</li>
</ul>
</li>
<li>
<a href="../news/index.html">Changelog</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>
<a href="https://github.com/ryantimpe/brickr">
<span class="fa fa-github fa-lg"></span>
</a>
</li>
</ul>
</div>
<!--/.nav-collapse -->
</div>
<!--/.container -->
</div>
<!--/.navbar -->
</header><div class="row">
<div class="col-md-9 contents">
<div class="page-header toc-ignore">
<h1>3D Models programmatically</h1>
<small class="dont-index">Source: <a href="https://github.com/ryantimpe/brickr/blob/master/vignettes/models-from-program.Rmd"><code>vignettes/models-from-program.Rmd</code></a></small>
<div class="hidden name"><code>models-from-program.Rmd</code></div>
</div>
<div id="getting-started" class="section level2">
<h2 class="hasAnchor">
<a href="#getting-started" class="anchor"></a>Getting started</h2>
<p>The <code>bricks_from_*</code> series of functions creates 3D models of LEGO bricks from a variety of input formats. These models are rendered using <a href="https://twitter.com/tylermorganwall">Tyler Morgan-Wall</a>s <a href="https://www.rayshader.com/">rayshader</a> package. This package must be installed.</p>
<p>Use <code><a href="../reference/bricks_from_coords.html">bricks_from_coords()</a></code> to programmatically build 3D LEGO models rather than manually drawing them in a spreadsheet or table. Prove the function with a data frame with x, y, and z coordinates, along with an official LEGO color name for each point.</p>
</div>
<div id="a-simple-programmed-model" class="section level2">
<h2 class="hasAnchor">
<a href="#a-simple-programmed-model" class="anchor"></a>A simple programmed model</h2>
<p>Below, we create a 8x8x8 cube by expanding a data frame with the array 1:8 as the x-, y-, and z-coordinates. We then assign each row of that data frame one of three colors: Bright blue, Bright yellow, or Bright red.</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb1-1" title="1">use_colors &lt;-<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="st">"Bright blue"</span>, <span class="st">"Bright yellow"</span>, <span class="st">"Bright red"</span>)</a>
<a class="sourceLine" id="cb1-2" title="2"></a>
<a class="sourceLine" id="cb1-3" title="3">cube &lt;-<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/expand.grid">expand.grid</a></span>(</a>
<a class="sourceLine" id="cb1-4" title="4"> <span class="dt">x =</span> <span class="dv">1</span><span class="op">:</span><span class="dv">8</span>,</a>
<a class="sourceLine" id="cb1-5" title="5"> <span class="dt">y =</span> <span class="dv">1</span><span class="op">:</span><span class="dv">8</span>,</a>
<a class="sourceLine" id="cb1-6" title="6"> <span class="dt">z =</span> <span class="dv">1</span><span class="op">:</span><span class="dv">8</span> </a>
<a class="sourceLine" id="cb1-7" title="7">) </a>
<a class="sourceLine" id="cb1-8" title="8"></a>
<a class="sourceLine" id="cb1-9" title="9">cube<span class="op">$</span>Color &lt;-<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/sample">sample</a></span>(use_colors, <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/nrow">nrow</a></span>(cube), <span class="dt">replace =</span> <span class="ot">TRUE</span>, <span class="dt">prob =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="dv">5</span>, <span class="dv">3</span>, <span class="dv">1</span>))</a>
<a class="sourceLine" id="cb1-10" title="10"></a>
<a class="sourceLine" id="cb1-11" title="11">cube <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb1-12" title="12"><span class="st"> </span><span class="kw"><a href="../reference/bricks_from_coords.html">bricks_from_coords</a></span>() <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb1-13" title="13"><span class="st"> </span><span class="kw"><a href="../reference/build_bricks.html">build_bricks</a></span>(<span class="dt">brick_res =</span> <span class="st">"hd"</span>, <span class="dt">phi =</span> <span class="dv">30</span>, <span class="dt">theta =</span> <span class="dv">30</span>)</a>
<a class="sourceLine" id="cb1-14" title="14"></a>
<a class="sourceLine" id="cb1-15" title="15">rayshader<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/rayshader/topics/render_snapshot">render_snapshot</a></span>(<span class="dt">clear =</span> <span class="ot">TRUE</span>)</a></code></pre></div>
<p><img src="../../../../OneDrive%20-%20LEGO/Documents/brickr/docs/articles/models-from-program_files/figure-html/bricks_6-1.png" width="384"></p>
<p>Using the same logic, we can build a sphere with a specified radius, and then apply rules to color each brick based on its coordinates.</p>
<div class="sourceCode" id="cb2"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb2-1" title="1">radius &lt;-<span class="st"> </span><span class="dv">4</span></a>
<a class="sourceLine" id="cb2-2" title="2">sphere_coords &lt;-<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/expand.grid">expand.grid</a></span>(</a>
<a class="sourceLine" id="cb2-3" title="3"> <span class="dt">x =</span> <span class="dv">1</span><span class="op">:</span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/Round">round</a></span>((radius<span class="op">*</span><span class="fl">2.5</span>)),</a>
<a class="sourceLine" id="cb2-4" title="4"> <span class="dt">y =</span> <span class="dv">1</span><span class="op">:</span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/Round">round</a></span>((radius<span class="op">*</span><span class="fl">2.5</span>)),</a>
<a class="sourceLine" id="cb2-5" title="5"> <span class="dt">z =</span> <span class="dv">1</span><span class="op">:</span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/Round">round</a></span>((radius<span class="op">/</span>(<span class="dv">6</span><span class="op">/</span><span class="dv">5</span>)<span class="op">*</span><span class="fl">2.5</span>)) <span class="co">#A brick is 6/5 taller than it is wide/deep</span></a>
<a class="sourceLine" id="cb2-6" title="6">) <span class="op">%&gt;%</span></a>
<a class="sourceLine" id="cb2-7" title="7"><span class="st"> </span>dplyr<span class="op">::</span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/mutate.html">mutate</a></span>(</a>
<a class="sourceLine" id="cb2-8" title="8"> <span class="co">#Distance of each coordinate from center</span></a>
<a class="sourceLine" id="cb2-9" title="9"> <span class="dt">dist =</span> (((x<span class="op">-</span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/mean">mean</a></span>(x))<span class="op">^</span><span class="dv">2</span> <span class="op">+</span><span class="st"> </span>(y<span class="op">-</span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/mean">mean</a></span>(y))<span class="op">^</span><span class="dv">2</span> <span class="op">+</span><span class="st"> </span>(z<span class="op">-</span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/mean">mean</a></span>(z))<span class="op">^</span><span class="dv">2</span>)<span class="op">^</span>(<span class="dv">1</span><span class="op">/</span><span class="dv">2</span>)),</a>
<a class="sourceLine" id="cb2-10" title="10"> <span class="dt">Color =</span> dplyr<span class="op">::</span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/case_when.html">case_when</a></span>(</a>
<a class="sourceLine" id="cb2-11" title="11"> <span class="co">#Yellow stripes on the surface with a 2to4 thickness</span></a>
<a class="sourceLine" id="cb2-12" title="12"> dplyr<span class="op">::</span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/between.html">between</a></span>(dist, (radius<span class="dv">-1</span>), radius) <span class="op">&amp;</span><span class="st"> </span>(x<span class="op">+</span>y<span class="op">+</span>z) <span class="op">%%</span><span class="st"> </span><span class="dv">6</span> <span class="op">%in%</span><span class="st"> </span><span class="dv">0</span><span class="op">:</span><span class="dv">1</span> <span class="op">~</span><span class="st"> "Bright yellow"</span>,</a>
<a class="sourceLine" id="cb2-13" title="13"> <span class="co">#Otherwise, sphere is blue</span></a>
<a class="sourceLine" id="cb2-14" title="14"> dist <span class="op">&lt;=</span><span class="st"> </span>radius <span class="op">~</span><span class="st"> "Bright blue"</span></a>
<a class="sourceLine" id="cb2-15" title="15"> ))</a>
<a class="sourceLine" id="cb2-16" title="16"></a>
<a class="sourceLine" id="cb2-17" title="17">sphere_coords <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb2-18" title="18"><span class="st"> </span><span class="kw"><a href="../reference/bricks_from_coords.html">bricks_from_coords</a></span>() <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb2-19" title="19"><span class="st"> </span><span class="kw"><a href="../reference/build_bricks.html">build_bricks</a></span>(<span class="dt">brick_res =</span> <span class="st">"hd"</span>, <span class="dt">phi =</span> <span class="dv">30</span>, <span class="dt">theta =</span> <span class="dv">30</span>)</a>
<a class="sourceLine" id="cb2-20" title="20"></a>
<a class="sourceLine" id="cb2-21" title="21">rayshader<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/rayshader/topics/render_snapshot">render_snapshot</a></span>(<span class="dt">clear =</span> <span class="ot">TRUE</span>)</a></code></pre></div>
<p><img src="../../../../OneDrive%20-%20LEGO/Documents/brickr/docs/articles/models-from-program_files/figure-html/bricks_7-1.png" width="384"></p>
</div>
<div id="it-takes-a-village" class="section level2">
<h2 class="hasAnchor">
<a href="#it-takes-a-village" class="anchor"></a>It takes a village</h2>
<p>Rather than directly writing a data frame for a model, you can write a function that returns a data frame with x, y, z, and Color coordinates given initial starting parameters.</p>
<p>Below, the function <code>brick_house()</code> creates a LEGO house with randomized colors. The x- and y-coordinates and the size of the house are inputs to the functions.</p>
<div class="sourceCode" id="cb3"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb3-1" title="1">brick_house &lt;-<span class="st"> </span><span class="cf">function</span>(<span class="dt">x_coord =</span> <span class="dv">0</span>, <span class="dt">y_coord =</span> <span class="dv">0</span>, <span class="dt">width=</span><span class="dv">6</span>, <span class="dt">length=</span><span class="dv">5</span>, <span class="dt">height=</span><span class="dv">6</span>){</a>
<a class="sourceLine" id="cb3-2" title="2"> roof_colors &lt;-<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="st">"Dark orange"</span>, <span class="st">"Dark brown"</span>, <span class="st">"Medium nougat"</span>, <span class="st">"Medium stone grey"</span>)</a>
<a class="sourceLine" id="cb3-3" title="3"> roof_col &lt;-<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/sample">sample</a></span>(roof_colors, <span class="dv">1</span>)</a>
<a class="sourceLine" id="cb3-4" title="4"> </a>
<a class="sourceLine" id="cb3-5" title="5"> house_colors &lt;-<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="st">"Bright blue"</span>, <span class="st">"Bright red"</span>, <span class="st">"Dark red"</span>, <span class="st">"Dark azur"</span>, <span class="st">"Nougat"</span>, <span class="st">"Bright reddish violet"</span>)</a>
<a class="sourceLine" id="cb3-6" title="6"> house_col &lt;-<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/sample">sample</a></span>(house_colors, <span class="dv">1</span>)</a>
<a class="sourceLine" id="cb3-7" title="7"> </a>
<a class="sourceLine" id="cb3-8" title="8"> house_coords &lt;-<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/expand.grid">expand.grid</a></span>(</a>
<a class="sourceLine" id="cb3-9" title="9"> <span class="dt">x =</span> <span class="dv">1</span><span class="op">:</span>width, <span class="dt">y =</span> <span class="dv">1</span><span class="op">:</span>length, <span class="dt">z =</span> (<span class="dv">1</span><span class="op">:</span>height)<span class="op">+</span><span class="dv">1</span></a>
<a class="sourceLine" id="cb3-10" title="10"> ) <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb3-11" title="11"><span class="st"> </span>dplyr<span class="op">::</span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/mutate.html">mutate</a></span>(</a>
<a class="sourceLine" id="cb3-12" title="12"> <span class="dt">roof =</span> (z <span class="op">&gt;</span><span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/Round">round</a></span>((<span class="dv">1</span><span class="op">/</span><span class="dv">2</span>)<span class="op">*</span>height)),</a>
<a class="sourceLine" id="cb3-13" title="13"> <span class="dt">Color =</span> dplyr<span class="op">::</span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/case_when.html">case_when</a></span>(</a>
<a class="sourceLine" id="cb3-14" title="14"> <span class="co">#Roof</span></a>
<a class="sourceLine" id="cb3-15" title="15"> roof <span class="op">&amp;</span><span class="st"> </span>(<span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/MathFun">abs</a></span>(y <span class="op">-</span><span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/Round">floor</a></span>(length<span class="op">/</span><span class="dv">2</span>) <span class="dv">-1</span>) <span class="op">&lt;=</span><span class="st"> </span>(height<span class="op">-</span>z)) <span class="op">~</span><span class="st"> </span>roof_col,</a>
<a class="sourceLine" id="cb3-16" title="16"> roof <span class="op">~</span><span class="st"> </span><span class="ot">NA_character_</span>,</a>
<a class="sourceLine" id="cb3-17" title="17"> <span class="co">#Door and windows</span></a>
<a class="sourceLine" id="cb3-18" title="18"> x <span class="op">==</span><span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/Round">round</a></span>(width<span class="op">/</span><span class="dv">2</span>) <span class="op">&amp;</span><span class="st"> </span>z <span class="op">==</span><span class="st"> </span><span class="dv">1</span> <span class="op">~</span><span class="st"> </span><span class="ot">NA_character_</span>,</a>
<a class="sourceLine" id="cb3-19" title="19"> dplyr<span class="op">::</span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/between.html">between</a></span>(x, <span class="dv">2</span>, width<span class="dv">-1</span>) <span class="op">&amp;</span><span class="st"> </span>x <span class="op">%%</span><span class="st"> </span><span class="dv">2</span> <span class="op">==</span><span class="st"> </span><span class="dv">0</span> <span class="op">&amp;</span><span class="st"> </span>y <span class="op">&gt;</span><span class="st"> </span><span class="dv">1</span> <span class="op">&amp;</span><span class="st"> </span>z <span class="op">==</span><span class="st"> </span><span class="dv">2</span> <span class="op">~</span><span class="st"> </span><span class="ot">NA_character_</span>,</a>
<a class="sourceLine" id="cb3-20" title="20"> dplyr<span class="op">::</span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/between.html">between</a></span>(y, <span class="dv">2</span>, length<span class="dv">-1</span>) <span class="op">&amp;</span><span class="st"> </span>y <span class="op">%%</span><span class="st"> </span><span class="dv">2</span> <span class="op">==</span><span class="st"> </span><span class="dv">0</span> <span class="op">&amp;</span><span class="st"> </span>z <span class="op">==</span><span class="st"> </span><span class="dv">2</span> <span class="op">~</span><span class="st"> </span><span class="ot">NA_character_</span>,</a>
<a class="sourceLine" id="cb3-21" title="21"> x <span class="op">%in%</span><span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="dv">1</span>, width) <span class="op">|</span><span class="st"> </span>y <span class="op">%in%</span><span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="dv">1</span>, length) <span class="op">~</span><span class="st"> </span>house_col),</a>
<a class="sourceLine" id="cb3-22" title="22"> <span class="dt">x =</span> x<span class="op">+</span>x_coord, </a>
<a class="sourceLine" id="cb3-23" title="23"> <span class="dt">y =</span> y<span class="op">+</span>y_coord</a>
<a class="sourceLine" id="cb3-24" title="24"> )</a>
<a class="sourceLine" id="cb3-25" title="25"> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/function">return</a></span>(house_coords)</a>
<a class="sourceLine" id="cb3-26" title="26">}</a>
<a class="sourceLine" id="cb3-27" title="27"></a>
<a class="sourceLine" id="cb3-28" title="28"><span class="co">#Build one house</span></a>
<a class="sourceLine" id="cb3-29" title="29"><span class="kw">brick_house</span>() <span class="op">%&gt;%</span><span class="st"> </span><span class="kw"><a href="../reference/bricks_from_coords.html">bricks_from_coords</a></span>() <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb3-30" title="30"><span class="st"> </span><span class="kw"><a href="../reference/build_bricks.html">build_bricks</a></span>(<span class="dt">theta =</span> <span class="dv">225</span>)</a>
<a class="sourceLine" id="cb3-31" title="31">rayshader<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/rayshader/topics/render_snapshot">render_snapshot</a></span>(<span class="dt">clear =</span> <span class="ot">TRUE</span>)</a></code></pre></div>
<p><img src="../../../../OneDrive%20-%20LEGO/Documents/brickr/docs/articles/models-from-program_files/figure-html/bricks_8-1.png" width="384"></p>
<p>Next, we write one more function, <code>brick_street()</code> to build a road and grass foundation. The, for an arbitrary number of houses and neighborhood size, use <code><a href="https://purrr.tidyverse.org/reference/map2.html">purrr::pmap_df</a></code> to generate many houses and place them along the road.</p>
<div class="sourceCode" id="cb4"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb4-1" title="1">brick_street &lt;-<span class="st"> </span><span class="cf">function</span>(<span class="dt">width =</span> <span class="dv">100</span>, <span class="dt">length =</span> <span class="dv">40</span>){</a>
<a class="sourceLine" id="cb4-2" title="2"> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/expand.grid">expand.grid</a></span>(<span class="dt">x=</span><span class="dv">1</span><span class="op">:</span>width, <span class="dt">y=</span><span class="dv">1</span><span class="op">:</span>length, <span class="dt">z=</span><span class="dv">1</span>) <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb4-3" title="3"><span class="st"> </span>dplyr<span class="op">::</span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/mutate.html">mutate</a></span>(</a>
<a class="sourceLine" id="cb4-4" title="4"> <span class="dt">Color =</span> dplyr<span class="op">::</span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/case_when.html">case_when</a></span>(</a>
<a class="sourceLine" id="cb4-5" title="5"> y <span class="op">==</span><span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/Round">round</a></span>(length<span class="op">/</span><span class="dv">2</span>) <span class="op">&amp;</span><span class="st"> </span>x <span class="op">%%</span><span class="st"> </span><span class="dv">4</span> <span class="op">%in%</span><span class="st"> </span><span class="dv">1</span><span class="op">:</span><span class="dv">4</span> <span class="op">~</span><span class="st"> "Bright yellow"</span>,</a>
<a class="sourceLine" id="cb4-6" title="6"> dplyr<span class="op">::</span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/between.html">between</a></span>(y, length<span class="op">/</span><span class="dv">2</span> <span class="dv">-5</span>, length<span class="op">/</span><span class="dv">2</span> <span class="op">+</span><span class="dv">5</span>) <span class="op">~</span><span class="st"> "Dark stone grey"</span>,</a>
<a class="sourceLine" id="cb4-7" title="7"> <span class="ot">TRUE</span> <span class="op">~</span><span class="st"> "Dark green"</span></a>
<a class="sourceLine" id="cb4-8" title="8"> ))</a>
<a class="sourceLine" id="cb4-9" title="9">}</a>
<a class="sourceLine" id="cb4-10" title="10"></a>
<a class="sourceLine" id="cb4-11" title="11"><span class="co">#Build a village, houses on 2 sides of a street</span></a>
<a class="sourceLine" id="cb4-12" title="12">n_houses =<span class="st"> </span><span class="dv">14</span></a>
<a class="sourceLine" id="cb4-13" title="13">sz =<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="dv">100</span>, <span class="dv">40</span>)</a>
<a class="sourceLine" id="cb4-14" title="14"></a>
<a class="sourceLine" id="cb4-15" title="15"><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/list">list</a></span>(<span class="dt">x_coord =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/sample">sample</a></span>(<span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/seq">seq</a></span>(<span class="dv">10</span>, sz[<span class="dv">1</span>]<span class="op">-</span><span class="dv">10</span>, <span class="dt">by =</span> <span class="dv">10</span>), n_houses<span class="op">/</span><span class="dv">2</span>),</a>
<a class="sourceLine" id="cb4-16" title="16"> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/sample">sample</a></span>(<span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/seq">seq</a></span>(<span class="dv">10</span>, sz[<span class="dv">1</span>]<span class="op">-</span><span class="dv">10</span>, <span class="dt">by =</span> <span class="dv">10</span>), n_houses<span class="op">/</span><span class="dv">2</span>)),</a>
<a class="sourceLine" id="cb4-17" title="17"> <span class="dt">y_coord =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/c">c</a></span>(<span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/rep">rep</a></span>(sz[<span class="dv">2</span>]<span class="op">/</span><span class="dv">2-15</span>, n_houses<span class="op">/</span><span class="dv">2</span>), <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/rep">rep</a></span>(sz[<span class="dv">2</span>]<span class="op">/</span><span class="dv">2</span><span class="op">+</span><span class="dv">10</span>, n_houses<span class="op">/</span><span class="dv">2</span>)),</a>
<a class="sourceLine" id="cb4-18" title="18"> <span class="dt">width =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/sample">sample</a></span>(<span class="dv">4</span><span class="op">:</span><span class="dv">10</span>, n_houses, <span class="dt">replace =</span> <span class="ot">TRUE</span>),</a>
<a class="sourceLine" id="cb4-19" title="19"> <span class="dt">length =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/sample">sample</a></span>(<span class="dv">4</span><span class="op">:</span><span class="dv">8</span>, n_houses, <span class="dt">replace =</span> <span class="ot">TRUE</span>),</a>
<a class="sourceLine" id="cb4-20" title="20"> <span class="dt">height =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/sample">sample</a></span>(<span class="dv">5</span><span class="op">:</span><span class="dv">8</span>, n_houses, <span class="dt">replace =</span> <span class="ot">TRUE</span>)</a>
<a class="sourceLine" id="cb4-21" title="21"> ) <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb4-22" title="22"><span class="st"> </span>purrr<span class="op">::</span><span class="kw"><a href="https://purrr.tidyverse.org/reference/map2.html">pmap_df</a></span>(brick_house) <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb4-23" title="23"><span class="st"> </span>dplyr<span class="op">::</span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/bind.html">bind_rows</a></span>(<span class="kw">brick_street</span>(sz[<span class="dv">1</span>], sz[<span class="dv">2</span>])) <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb4-24" title="24"><span class="st"> </span><span class="kw"><a href="../reference/bricks_from_coords.html">bricks_from_coords</a></span>() <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb4-25" title="25"><span class="st"> </span><span class="kw"><a href="../reference/build_bricks.html">build_bricks</a></span>()</a>
<a class="sourceLine" id="cb4-26" title="26"></a>
<a class="sourceLine" id="cb4-27" title="27">rayshader<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/rayshader/topics/render_camera">render_camera</a></span>(<span class="dt">theta =</span> <span class="dv">60</span>, <span class="dt">phi =</span> <span class="dv">20</span>, <span class="dt">zoom =</span> <span class="fl">0.75</span>)</a>
<a class="sourceLine" id="cb4-28" title="28">rayshader<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/rayshader/topics/render_snapshot">render_snapshot</a></span>(<span class="dt">clear =</span> <span class="ot">TRUE</span>)</a></code></pre></div>
<p><img src="../../../../OneDrive%20-%20LEGO/Documents/brickr/docs/articles/models-from-program_files/figure-html/bricks_9-1.png" width="384"></p>
</div>
</div>
<div class="col-md-3 hidden-xs hidden-sm" id="sidebar">
<div id="tocnav">
<h2 class="hasAnchor">
<a href="#tocnav" class="anchor"></a>Contents</h2>
<ul class="nav nav-pills nav-stacked">
<li><a href="#getting-started">Getting started</a></li>
<li><a href="#a-simple-programmed-model">A simple programmed model</a></li>
<li><a href="#it-takes-a-village">It takes a village</a></li>
</ul>
</div>
</div>
</div>
<footer><div class="copyright">
<p>Developed by Ryan Timpe.</p>
</div>
<div class="pkgdown">
<p>Site built with <a href="https://pkgdown.r-lib.org/">pkgdown</a> 1.3.0.</p>
</div>
</footer>
</div>
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 137 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 123 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 144 KiB

View File

@@ -0,0 +1,261 @@
<!DOCTYPE html>
<!-- Generated by pkgdown: do not edit by hand --><html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>3D models from tables • brickr</title>
<!-- favicons --><link rel="icon" type="image/png" sizes="16x16" href="../favicon-16x16.png">
<link rel="icon" type="image/png" sizes="32x32" href="../favicon-32x32.png">
<link rel="apple-touch-icon" type="image/png" sizes="180x180" href="../apple-touch-icon.png">
<link rel="apple-touch-icon" type="image/png" sizes="120x120" href="../apple-touch-icon-120x120.png">
<link rel="apple-touch-icon" type="image/png" sizes="76x76" href="../apple-touch-icon-76x76.png">
<link rel="apple-touch-icon" type="image/png" sizes="60x60" href="../apple-touch-icon-60x60.png">
<!-- jquery --><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script><!-- Bootstrap --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha256-916EbMg70RQy9LHiGkXzG8hSg9EdNy97GazNG/aiY1w=" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha256-U5ZEeKfGNOja007MMD3YBI0A3OSZOQbeG6z2f2Y0hu8=" crossorigin="anonymous"></script><!-- Font Awesome icons --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" integrity="sha256-eZrrJcwDc/3uDhsdt61sL2oOBY362qM3lon1gyExkL0=" crossorigin="anonymous">
<!-- clipboard.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.4/clipboard.min.js" integrity="sha256-FiZwavyI2V6+EXO1U+xzLG3IKldpiTFf3153ea9zikQ=" crossorigin="anonymous"></script><!-- sticky kit --><script src="https://cdnjs.cloudflare.com/ajax/libs/sticky-kit/1.1.3/sticky-kit.min.js" integrity="sha256-c4Rlo1ZozqTPE2RLuvbusY3+SU1pQaJC0TjuhygMipw=" crossorigin="anonymous"></script><!-- pkgdown --><link href="../pkgdown.css" rel="stylesheet">
<script src="../pkgdown.js"></script><meta property="og:title" content="3D models from tables">
<meta property="og:description" content="">
<meta property="og:image" content="http://brickr.org/logo.png">
<meta name="twitter:card" content="summary">
<!-- mathjax --><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script><!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container template-article">
<header><div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">brickr</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9014</span>
</span>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>
<a href="../index.html">
<span class="fa fa-home fa-lg"></span>
</a>
</li>
<li>
<a href="../reference/index.html">Reference</a>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
Articles
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="../articles/graphs.html">ggplot with brickr</a>
</li>
<li>
<a href="../articles/models-from-other.html">3D Models from mosaics &amp; rayshader</a>
</li>
<li>
<a href="../articles/models-from-program.html">3D Models programmatically</a>
</li>
<li>
<a href="../articles/models-from-tables.html">3D models from tables</a>
</li>
<li>
<a href="../articles/mosaics.html">Mosaics with brickr</a>
</li>
</ul>
</li>
<li>
<a href="../news/index.html">Changelog</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>
<a href="https://github.com/ryantimpe/brickr">
<span class="fa fa-github fa-lg"></span>
</a>
</li>
</ul>
</div>
<!--/.nav-collapse -->
</div>
<!--/.container -->
</div>
<!--/.navbar -->
</header><div class="row">
<div class="col-md-9 contents">
<div class="page-header toc-ignore">
<h1>3D models from tables</h1>
<small class="dont-index">Source: <a href="https://github.com/ryantimpe/brickr/blob/master/vignettes/models-from-tables.Rmd"><code>vignettes/models-from-tables.Rmd</code></a></small>
<div class="hidden name"><code>models-from-tables.Rmd</code></div>
</div>
<div id="getting-started" class="section level2">
<h2 class="hasAnchor">
<a href="#getting-started" class="anchor"></a>Getting started</h2>
<p>The <code>bricks_from_*</code> series of functions creates 3D models of LEGO bricks from a variety of input formats. These models are rendered using <a href="https://twitter.com/tylermorganwall">Tyler Morgan-Wall</a>s <a href="https://www.rayshader.com/">rayshader</a> package. This package must be installed.</p>
<p><code><a href="../reference/bricks_from_table.html">bricks_from_table()</a></code> converts a matrix-shaped table of integers into LEGO bricks, where most columns are x-coordinates, rows are y-coordinates, and a special <code>Level</code> column denotes the elevation of the row. For simple models, this table can be made manually using <code><a href="https://www.rdocumentation.org/packages/base/topics/data.frame">data.frame()</a></code> or <code><a href="https://tibble.tidyverse.org/reference/tribble.html">tibble::tribble()</a></code>.</p>
<p>For more advanced models, its recommended you use MS Excel or a .csv file. <code><a href="../reference/bricks_from_excel.html">bricks_from_excel()</a></code> is a wrapper function to more easily build models designed using a Microsoft Excel template. Please see this repo: <a href="https://github.com/ryantimpe/brickr_toybox">brickr toybox</a>.</p>
<p>Pass the output of any <code>bricks_from_*()</code> function to <code><a href="../reference/build_bricks.html">build_bricks()</a></code> to render it as a 3D model.</p>
</div>
<div id="individual-bricks" class="section level2">
<h2 class="hasAnchor">
<a href="#individual-bricks" class="anchor"></a>Individual bricks</h2>
<p>Create a single 2x4 brick with a 2x4 data frame, with an additional column to specify the Level. These can be letters or numbers.</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb1-1" title="1"><span class="co">#This is a 2 (columns) x 4 (rows) brick</span></a>
<a class="sourceLine" id="cb1-2" title="2">(brick &lt;-<span class="st"> </span><span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/data.frame">data.frame</a></span>(</a>
<a class="sourceLine" id="cb1-3" title="3"> <span class="dt">Level=</span><span class="st">"A"</span>,</a>
<a class="sourceLine" id="cb1-4" title="4"> <span class="dt">X1 =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/rep">rep</a></span>(<span class="dv">3</span>,<span class="dv">4</span>), <span class="co">#The number 3 is the brickrID for 'bright red'</span></a>
<a class="sourceLine" id="cb1-5" title="5"> <span class="dt">X2 =</span> <span class="kw"><a href="https://www.rdocumentation.org/packages/base/topics/rep">rep</a></span>(<span class="dv">3</span>,<span class="dv">4</span>)</a>
<a class="sourceLine" id="cb1-6" title="6">))</a>
<a class="sourceLine" id="cb1-7" title="7"><span class="co">#&gt; Level X1 X2</span></a>
<a class="sourceLine" id="cb1-8" title="8"><span class="co">#&gt; 1 A 3 3</span></a>
<a class="sourceLine" id="cb1-9" title="9"><span class="co">#&gt; 2 A 3 3</span></a>
<a class="sourceLine" id="cb1-10" title="10"><span class="co">#&gt; 3 A 3 3</span></a>
<a class="sourceLine" id="cb1-11" title="11"><span class="co">#&gt; 4 A 3 3</span></a>
<a class="sourceLine" id="cb1-12" title="12"></a>
<a class="sourceLine" id="cb1-13" title="13">brick <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb1-14" title="14"><span class="st"> </span><span class="kw"><a href="../reference/bricks_from_table.html">bricks_from_table</a></span>() <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb1-15" title="15"><span class="st"> </span><span class="kw"><a href="../reference/build_bricks.html">build_bricks</a></span>(<span class="dt">brick_res =</span> <span class="st">"hd"</span>) <span class="co">#Bricks available in standard def, high def, and ultra hd. </span></a>
<a class="sourceLine" id="cb1-16" title="16"></a>
<a class="sourceLine" id="cb1-17" title="17">rayshader<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/rayshader/topics/render_snapshot">render_snapshot</a></span>( <span class="dt">clear =</span> <span class="ot">TRUE</span>)</a></code></pre></div>
<p><img src="../../../../OneDrive%20-%20LEGO/Documents/brickr/docs/articles/models-from-tables_files/figure-html/bricks_1-1.png" width="288"></p>
<p>Stack many bricks by changing the Level value in the data frame. The script below uses <code><a href="https://purrr.tidyverse.org/reference/map.html">purrr::map_df()</a></code> to avoid copying and pasting. Changing the numeric values inside the data frame for each level creates different colors.</p>
<div class="sourceCode" id="cb2"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb2-1" title="1"><span class="dv">1</span><span class="op">:</span><span class="dv">10</span> <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb2-2" title="2"><span class="st"> </span>purrr<span class="op">::</span><span class="kw"><a href="https://purrr.tidyverse.org/reference/map.html">map_df</a></span>(<span class="op">~</span>dplyr<span class="op">::</span><span class="kw"><a href="https://dplyr.tidyverse.org/reference/mutate.html">mutate</a></span>(brick,</a>
<a class="sourceLine" id="cb2-3" title="3"> <span class="dt">Level =</span> LETTERS[.x], </a>
<a class="sourceLine" id="cb2-4" title="4"> <span class="dt">X1 =</span> .x,</a>
<a class="sourceLine" id="cb2-5" title="5"> <span class="dt">X2 =</span> .x)) <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb2-6" title="6"><span class="st"> </span><span class="kw"><a href="../reference/bricks_from_table.html">bricks_from_table</a></span>() <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb2-7" title="7"><span class="st"> </span><span class="kw"><a href="../reference/build_bricks.html">build_bricks</a></span>(<span class="dt">brick_res =</span> <span class="st">"hd"</span>)</a>
<a class="sourceLine" id="cb2-8" title="8"></a>
<a class="sourceLine" id="cb2-9" title="9">rayshader<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/rayshader/topics/render_snapshot">render_snapshot</a></span>( <span class="dt">clear =</span> <span class="ot">TRUE</span>)</a></code></pre></div>
<p><img src="../../../../OneDrive%20-%20LEGO/Documents/brickr/docs/articles/models-from-tables_files/figure-html/bricks_2-1.png" width="288"></p>
</div>
<div id="full-models" class="section level2">
<h2 class="hasAnchor">
<a href="#full-models" class="anchor"></a>Full models</h2>
<p>The most direct way to create a 3D model is to manually create a data frame. Below, we create a data frame using <code><a href="https://tibble.tidyverse.org/reference/tribble.html">tibble::tribble()</a></code> so we can more easily see the structure as its written.</p>
<p>The data frame has 3 numbers as input (values of 0 are void spaces in the model). Rather than use the default brickr colors for the values of 1, 2, and 3, we define another data frame brick_colors</p>
<div class="sourceCode" id="cb3"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb3-1" title="1">tree_or_mushroom &lt;-<span class="st"> </span>tibble<span class="op">::</span><span class="kw"><a href="https://tibble.tidyverse.org/reference/tribble.html">tribble</a></span>(</a>
<a class="sourceLine" id="cb3-2" title="2"> <span class="op">~</span>Level, <span class="op">~</span>X1, <span class="op">~</span>X2, <span class="op">~</span>X3, <span class="op">~</span>X4, <span class="op">~</span>X5, <span class="op">~</span>X6,</a>
<a class="sourceLine" id="cb3-3" title="3"> <span class="st">"A"</span>, <span class="dv">1</span>, <span class="dv">1</span>, <span class="dv">1</span>, <span class="dv">1</span>, <span class="dv">1</span>, <span class="dv">1</span>, </a>
<a class="sourceLine" id="cb3-4" title="4"> <span class="st">"A"</span>, <span class="dv">1</span>, <span class="dv">1</span>, <span class="dv">1</span>, <span class="dv">1</span>, <span class="dv">1</span>, <span class="dv">1</span>, </a>
<a class="sourceLine" id="cb3-5" title="5"> <span class="st">"A"</span>, <span class="dv">1</span>, <span class="dv">1</span>, <span class="dv">1</span>, <span class="dv">1</span>, <span class="dv">1</span>, <span class="dv">1</span>, </a>
<a class="sourceLine" id="cb3-6" title="6"> <span class="st">"A"</span>, <span class="dv">1</span>, <span class="dv">1</span>, <span class="dv">1</span>, <span class="dv">1</span>, <span class="dv">1</span>, <span class="dv">1</span>, </a>
<a class="sourceLine" id="cb3-7" title="7"> <span class="st">"B"</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, </a>
<a class="sourceLine" id="cb3-8" title="8"> <span class="st">"B"</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">2</span>, <span class="dv">2</span>, <span class="dv">0</span>, <span class="dv">0</span>,</a>
<a class="sourceLine" id="cb3-9" title="9"> <span class="st">"B"</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">2</span>, <span class="dv">2</span>, <span class="dv">0</span>, <span class="dv">0</span>, </a>
<a class="sourceLine" id="cb3-10" title="10"> <span class="st">"B"</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, </a>
<a class="sourceLine" id="cb3-11" title="11"> <span class="st">"C"</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, </a>
<a class="sourceLine" id="cb3-12" title="12"> <span class="st">"C"</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">2</span>, <span class="dv">2</span>, <span class="dv">0</span>, <span class="dv">0</span>,</a>
<a class="sourceLine" id="cb3-13" title="13"> <span class="st">"C"</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">2</span>, <span class="dv">2</span>, <span class="dv">0</span>, <span class="dv">0</span>, </a>
<a class="sourceLine" id="cb3-14" title="14"> <span class="st">"C"</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, </a>
<a class="sourceLine" id="cb3-15" title="15"> <span class="st">"D"</span>, <span class="dv">0</span>, <span class="dv">3</span>, <span class="dv">3</span>, <span class="dv">3</span>, <span class="dv">3</span>, <span class="dv">0</span>, </a>
<a class="sourceLine" id="cb3-16" title="16"> <span class="st">"D"</span>, <span class="dv">0</span>, <span class="dv">3</span>, <span class="dv">3</span>, <span class="dv">3</span>, <span class="dv">3</span>, <span class="dv">0</span>,</a>
<a class="sourceLine" id="cb3-17" title="17"> <span class="st">"D"</span>, <span class="dv">0</span>, <span class="dv">3</span>, <span class="dv">3</span>, <span class="dv">3</span>, <span class="dv">3</span>, <span class="dv">0</span>, </a>
<a class="sourceLine" id="cb3-18" title="18"> <span class="st">"D"</span>, <span class="dv">0</span>, <span class="dv">3</span>, <span class="dv">3</span>, <span class="dv">3</span>, <span class="dv">3</span>, <span class="dv">0</span>,</a>
<a class="sourceLine" id="cb3-19" title="19"> <span class="st">"E"</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">3</span>, <span class="dv">3</span>, <span class="dv">0</span>, <span class="dv">0</span>, </a>
<a class="sourceLine" id="cb3-20" title="20"> <span class="st">"E"</span>, <span class="dv">0</span>, <span class="dv">3</span>, <span class="dv">3</span>, <span class="dv">3</span>, <span class="dv">3</span>, <span class="dv">0</span>,</a>
<a class="sourceLine" id="cb3-21" title="21"> <span class="st">"E"</span>, <span class="dv">0</span>, <span class="dv">3</span>, <span class="dv">3</span>, <span class="dv">3</span>, <span class="dv">3</span>, <span class="dv">0</span>, </a>
<a class="sourceLine" id="cb3-22" title="22"> <span class="st">"E"</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">3</span>, <span class="dv">3</span>, <span class="dv">0</span>, <span class="dv">0</span>,</a>
<a class="sourceLine" id="cb3-23" title="23"> <span class="st">"F"</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, </a>
<a class="sourceLine" id="cb3-24" title="24"> <span class="st">"F"</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">3</span>, <span class="dv">3</span>, <span class="dv">0</span>, <span class="dv">0</span>,</a>
<a class="sourceLine" id="cb3-25" title="25"> <span class="st">"F"</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">3</span>, <span class="dv">3</span>, <span class="dv">0</span>, <span class="dv">0</span>, </a>
<a class="sourceLine" id="cb3-26" title="26"> <span class="st">"F"</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>,</a>
<a class="sourceLine" id="cb3-27" title="27"> <span class="st">"G"</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, </a>
<a class="sourceLine" id="cb3-28" title="28"> <span class="st">"G"</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">3</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>,</a>
<a class="sourceLine" id="cb3-29" title="29"> <span class="st">"G"</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">3</span>, <span class="dv">0</span>, <span class="dv">0</span>, </a>
<a class="sourceLine" id="cb3-30" title="30"> <span class="st">"G"</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span>, <span class="dv">0</span></a>
<a class="sourceLine" id="cb3-31" title="31">)</a>
<a class="sourceLine" id="cb3-32" title="32"></a>
<a class="sourceLine" id="cb3-33" title="33">brick_colors &lt;-<span class="st"> </span>tibble<span class="op">::</span><span class="kw"><a href="https://tibble.tidyverse.org/reference/tribble.html">tribble</a></span>(</a>
<a class="sourceLine" id="cb3-34" title="34"> <span class="op">~</span><span class="st">`</span><span class="dt">.value</span><span class="st">`</span>, <span class="op">~</span>Color,</a>
<a class="sourceLine" id="cb3-35" title="35"> <span class="dv">1</span>, <span class="st">"Bright green"</span>,</a>
<a class="sourceLine" id="cb3-36" title="36"> <span class="dv">2</span>, <span class="st">"Dark orange"</span>,</a>
<a class="sourceLine" id="cb3-37" title="37"> <span class="dv">3</span>, <span class="st">"Dark green"</span></a>
<a class="sourceLine" id="cb3-38" title="38">)</a>
<a class="sourceLine" id="cb3-39" title="39"> </a>
<a class="sourceLine" id="cb3-40" title="40">tree_or_mushroom <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb3-41" title="41"><span class="st"> </span><span class="kw"><a href="../reference/bricks_from_table.html">bricks_from_table</a></span>(brick_colors) <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb3-42" title="42"><span class="st"> </span><span class="kw"><a href="../reference/build_bricks.html">build_bricks</a></span>(<span class="dt">theta =</span> <span class="dv">210</span>, <span class="dt">phi =</span> <span class="dv">20</span>, <span class="dt">brick_res =</span> <span class="st">"hd"</span>)</a>
<a class="sourceLine" id="cb3-43" title="43"></a>
<a class="sourceLine" id="cb3-44" title="44">rayshader<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/rayshader/topics/render_snapshot">render_snapshot</a></span>(<span class="dt">clear =</span> <span class="ot">TRUE</span>)</a></code></pre></div>
<p><img src="../../../../OneDrive%20-%20LEGO/Documents/brickr/docs/articles/models-from-tables_files/figure-html/bricks_5-1.png" width="384"></p>
<div id="plates-instead-of-bricks" class="section level3">
<h3 class="hasAnchor">
<a href="#plates-instead-of-bricks" class="anchor"></a>Plates instead of bricks</h3>
<p>Thats clearly a tree, right? Why is the data frame called tree_or_mushroom?</p>
<p>Use the input brick_type=“plate” to render the 3D model using LEGO plates rather than bricks, which are 1/3 as tall.</p>
<div class="sourceCode" id="cb4"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb4-1" title="1">brick_colors &lt;-<span class="st"> </span>tibble<span class="op">::</span><span class="kw"><a href="https://tibble.tidyverse.org/reference/tribble.html">tribble</a></span>(</a>
<a class="sourceLine" id="cb4-2" title="2"> <span class="op">~</span><span class="st">`</span><span class="dt">.value</span><span class="st">`</span>, <span class="op">~</span>Color,</a>
<a class="sourceLine" id="cb4-3" title="3"> <span class="dv">1</span>, <span class="st">"Dark green"</span>,</a>
<a class="sourceLine" id="cb4-4" title="4"> <span class="dv">2</span>, <span class="st">"Light nougat"</span>,</a>
<a class="sourceLine" id="cb4-5" title="5"> <span class="dv">3</span>, <span class="st">"Bright red"</span></a>
<a class="sourceLine" id="cb4-6" title="6">)</a>
<a class="sourceLine" id="cb4-7" title="7"> </a>
<a class="sourceLine" id="cb4-8" title="8">tree_or_mushroom <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb4-9" title="9"><span class="st"> </span><span class="kw"><a href="../reference/bricks_from_table.html">bricks_from_table</a></span>(brick_colors) <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb4-10" title="10"><span class="st"> </span><span class="kw"><a href="../reference/build_bricks.html">build_bricks</a></span>(<span class="dt">theta =</span> <span class="dv">210</span>, <span class="dt">phi =</span> <span class="dv">10</span>, <span class="dt">brick_res =</span> <span class="st">"hd"</span>, <span class="dt">brick_type=</span><span class="st">"plate"</span>)</a>
<a class="sourceLine" id="cb4-11" title="11"></a>
<a class="sourceLine" id="cb4-12" title="12">rayshader<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/rayshader/topics/render_snapshot">render_snapshot</a></span>(<span class="dt">clear =</span> <span class="ot">TRUE</span>)</a></code></pre></div>
<p><img src="../../../../OneDrive%20-%20LEGO/Documents/brickr/docs/articles/models-from-tables_files/figure-html/bricks_5a-1.png" width="384"></p>
</div>
</div>
<div id="bricks-from-excel" class="section level2">
<h2 class="hasAnchor">
<a href="#bricks-from-excel" class="anchor"></a>Bricks from Excel</h2>
<p>When designing larger models, it is much easier to use a spreadsheet program to lay out the bricks for each level.</p>
<p>See <a href="https://github.com/ryantimpe/brickr_toybox">the brickr toybox</a> GitHub repo for some examples and templates.</p>
</div>
</div>
<div class="col-md-3 hidden-xs hidden-sm" id="sidebar">
<div id="tocnav">
<h2 class="hasAnchor">
<a href="#tocnav" class="anchor"></a>Contents</h2>
<ul class="nav nav-pills nav-stacked">
<li><a href="#getting-started">Getting started</a></li>
<li><a href="#individual-bricks">Individual bricks</a></li>
<li><a href="#full-models">Full models</a></li>
<li><a href="#bricks-from-excel">Bricks from Excel</a></li>
</ul>
</div>
</div>
</div>
<footer><div class="copyright">
<p>Developed by Ryan Timpe.</p>
</div>
<div class="pkgdown">
<p>Site built with <a href="https://pkgdown.r-lib.org/">pkgdown</a> 1.3.0.</p>
</div>
</footer>
</div>
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

View File

@@ -37,7 +37,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">brickr</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9011</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9014</span>
</span>
</div>
@@ -62,6 +62,15 @@
<li>
<a href="../articles/graphs.html">ggplot with brickr</a>
</li>
<li>
<a href="../articles/models-from-other.html">3D Models from mosaics &amp; rayshader</a>
</li>
<li>
<a href="../articles/models-from-program.html">3D Models programmatically</a>
</li>
<li>
<a href="../articles/models-from-tables.html">3D models from tables</a>
</li>
<li>
<a href="../articles/mosaics.html">Mosaics with brickr</a>
</li>

View File

@@ -70,7 +70,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="index.html">brickr</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9011</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9014</span>
</span>
</div>
@@ -95,6 +95,15 @@
<li>
<a href="articles/graphs.html">ggplot with brickr</a>
</li>
<li>
<a href="articles/models-from-other.html">3D Models from mosaics &amp; rayshader</a>
</li>
<li>
<a href="articles/models-from-program.html">3D Models programmatically</a>
</li>
<li>
<a href="articles/models-from-tables.html">3D models from tables</a>
</li>
<li>
<a href="articles/mosaics.html">Mosaics with brickr</a>
</li>

View File

@@ -39,7 +39,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="index.html">brickr</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9011</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9014</span>
</span>
</div>
@@ -64,6 +64,15 @@
<li>
<a href="articles/graphs.html">ggplot with brickr</a>
</li>
<li>
<a href="articles/models-from-other.html">3D Models from mosaics &amp; rayshader</a>
</li>
<li>
<a href="articles/models-from-program.html">3D Models programmatically</a>
</li>
<li>
<a href="articles/models-from-tables.html">3D models from tables</a>
</li>
<li>
<a href="articles/mosaics.html">Mosaics with brickr</a>
</li>
@@ -115,8 +124,18 @@
<a href="#charts"><strong>Charts</strong></a>: A <a href="https://ggplot2.tidyverse.org/">ggplot2</a> extension to generate plots that resemble LEGO® bricks.</li>
</ul>
<p>brickr also includes tools help users create the Mosaics and 3D model output using real LEGO® elements.</p>
<div id="whats-the-point" class="section level3">
<h3 class="hasAnchor">
<a href="#whats-the-point" class="anchor"></a>Whats the point?</h3>
<p>The goal of {brickr} is to provide a series of tools to integrate the LEGO® system with R by:</p>
<ul>
<li>Enhancing a real world building experience with mosaics, generated instructions, and piece counts.</li>
<li>Generating interest in R and coding for new audiences with easy-to-create 3D models.</li>
<li>or just embracing pure novelty.</li>
</ul>
<p><em>brickr is developed using publicly available information about LEGO® products and is not officially affiliated with The LEGO Group</em></p>
</div>
</div>
<div id="installation" class="section level2">
<h2 class="hasAnchor">
<a href="#installation" class="anchor"></a>Installation</h2>
@@ -172,7 +191,7 @@
<a class="sourceLine" id="cb3-11" title="11"><span class="st"> </span><span class="kw"><a href="reference/bricks_from_table.html">bricks_from_table</a></span>() <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb3-12" title="12"><span class="st"> </span><span class="kw"><a href="reference/build_bricks.html">build_bricks</a></span>(<span class="dt">brick_res =</span> <span class="st">"uhd"</span>)</a>
<a class="sourceLine" id="cb3-13" title="13"></a>
<a class="sourceLine" id="cb3-14" title="14">rayshader<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/rayshader/topics/render_snapshot">render_snapshot</a></span>()</a></code></pre></div>
<a class="sourceLine" id="cb3-14" title="14">rayshader<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/rayshader/topics/render_snapshot">render_snapshot</a></span>( <span class="dt">clear =</span> <span class="ot">TRUE</span>)</a></code></pre></div>
<p><img src="../../../OneDrive%20-%20LEGO/Documents/brickr/docs/index_files/figure-html/bricks_1-1.png" width="288"></p>
<div id="stacking-bricks" class="section level3">
<h3 class="hasAnchor">
@@ -213,7 +232,7 @@
<a class="sourceLine" id="cb4-32" title="32"><span class="st"> </span><span class="kw"><a href="reference/bricks_from_table.html">bricks_from_table</a></span>(brick_colors) <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb4-33" title="33"><span class="st"> </span><span class="kw"><a href="reference/build_bricks.html">build_bricks</a></span>(<span class="dt">theta =</span> <span class="dv">210</span>, <span class="dt">brick_res =</span> <span class="st">"hd"</span>)</a>
<a class="sourceLine" id="cb4-34" title="34"></a>
<a class="sourceLine" id="cb4-35" title="35">rayshader<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/rayshader/topics/render_snapshot">render_snapshot</a></span>()</a></code></pre></div>
<a class="sourceLine" id="cb4-35" title="35">rayshader<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/rayshader/topics/render_snapshot">render_snapshot</a></span>(<span class="dt">clear =</span> <span class="ot">TRUE</span>)</a></code></pre></div>
<p><img src="../../../OneDrive%20-%20LEGO/Documents/brickr/docs/index_files/figure-html/bricks_5-1.png" width="384"></p>
</div>
<div id="programmatically-build-models" class="section level3">
@@ -240,7 +259,7 @@
<a class="sourceLine" id="cb5-18" title="18"><span class="st"> </span><span class="kw"><a href="reference/bricks_from_coords.html">bricks_from_coords</a></span>() <span class="op">%&gt;%</span><span class="st"> </span></a>
<a class="sourceLine" id="cb5-19" title="19"><span class="st"> </span><span class="kw"><a href="reference/build_bricks.html">build_bricks</a></span>(<span class="dt">phi =</span> <span class="dv">30</span>, <span class="dt">theta =</span> <span class="dv">30</span>)</a>
<a class="sourceLine" id="cb5-20" title="20"></a>
<a class="sourceLine" id="cb5-21" title="21">rayshader<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/rayshader/topics/render_snapshot">render_snapshot</a></span>()</a></code></pre></div>
<a class="sourceLine" id="cb5-21" title="21">rayshader<span class="op">::</span><span class="kw"><a href="https://www.rdocumentation.org/packages/rayshader/topics/render_snapshot">render_snapshot</a></span>(<span class="dt">clear =</span> <span class="ot">TRUE</span>)</a></code></pre></div>
<p><img src="../../../OneDrive%20-%20LEGO/Documents/brickr/docs/index_files/figure-html/bricks_6-1.png" width="480"></p>
</div>
<div id="examples" class="section level3">
@@ -333,7 +352,7 @@
<div class="dev-status">
<h2>Dev status</h2>
<ul class="list-unstyled">
<li><a href="https://www.tidyverse.org/lifecycle/#maturing"><img src="https://img.shields.io/badge/lifecycle-maturing-blue.svg" alt="Lifecycle: maturing"></a></li>
<li><a href="https://www.tidyverse.org/lifecycle/#experimental"><img src="https://img.shields.io/badge/lifecycle-experimental-orange.svg" alt="Lifecycle: experimental"></a></li>
</ul>
</div>
</div>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 46 KiB

After

Width:  |  Height:  |  Size: 47 KiB

View File

@@ -70,7 +70,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">brickr</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9011</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9014</span>
</span>
</div>
@@ -95,6 +95,15 @@
<li>
<a href="../articles/graphs.html">ggplot with brickr</a>
</li>
<li>
<a href="../articles/models-from-other.html">3D Models from mosaics &amp; rayshader</a>
</li>
<li>
<a href="../articles/models-from-program.html">3D Models programmatically</a>
</li>
<li>
<a href="../articles/models-from-tables.html">3D models from tables</a>
</li>
<li>
<a href="../articles/mosaics.html">Mosaics with brickr</a>
</li>
@@ -135,16 +144,12 @@
<li><p><strong>Breaking:</strong> Pretty much <em>EVERY</em> function. Seriously, check out the README and start fresh.</p></li>
<li><p><strong>Breaking:</strong> Data “lego_colors.rda” has been updated with more accurate RGB values and new <code>brickrID</code> numbers. This will impact previously created mosaics and 3D models.</p></li>
</ul>
<div id="documentations" class="section level2">
<div id="documentation" class="section level2">
<h2 class="hasAnchor">
<a href="#documentations" class="anchor"></a>Documentations</h2>
<a href="#documentation" class="anchor"></a>Documentation</h2>
<ul>
<li>pkgdown site</li>
<li>Vignettes:
<ul>
<li>Mosaics</li>
</ul>
</li>
<li>Vignettes</li>
</ul>
</div>
<div id="mosaics" class="section level2">
@@ -170,6 +175,8 @@
<li>Option to use plates rather than bricks. Combining the two involves some hacking.</li>
<li>Updated brick collection algorithm to allow for custom brick input.</li>
<li>Updated brick collection algorithm staggers bricks over layer, though still prioritizes larger bricks.</li>
<li>
<code>build_instructions</code> generates building instructions for 3D models, as well as mosaics.</li>
</ul>
</div>
<div id="ggplot-extension" class="section level2">
@@ -189,13 +196,9 @@
<a href="#to-do" class="anchor"></a>TO DO</h2>
<ul>
<li><p>ggplot - continuous scale</p></li>
<li>3D model instructions… level by level</li>
<li>Vignettes
<ul>
<li>3D models from tables</li>
<li>3D models from coords</li>
<li>3D modesl from mosaics + rayshader</li>
<li>ggplot</li>
<li>3D model from mosaics + rayshader</li>
<li>IRL</li>
</ul>
</li>

View File

@@ -3,6 +3,9 @@ pkgdown: 1.3.0
pkgdown_sha: ~
articles:
graphs: ../../../../Onedrive - LEGO/Documents/brickr/vignettes/graphs.html
models-from-other: ../../../../Onedrive - LEGO/Documents/brickr/vignettes/models-from-other.html
models-from-program: ../../../../Onedrive - LEGO/Documents/brickr/vignettes/models-from-program.html
models-from-tables: ../../../../Onedrive - LEGO/Documents/brickr/vignettes/models-from-tables.html
mosaics: ../../../../Onedrive - LEGO/Documents/brickr/vignettes/mosaics.html
urls:
reference: http://brickr.org/reference

View File

@@ -72,7 +72,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">brickr</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9011</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9014</span>
</span>
</div>
@@ -97,6 +97,15 @@
<li>
<a href="../articles/graphs.html">ggplot with brickr</a>
</li>
<li>
<a href="../articles/models-from-other.html">3D Models from mosaics &amp; rayshader</a>
</li>
<li>
<a href="../articles/models-from-program.html">3D Models programmatically</a>
</li>
<li>
<a href="../articles/models-from-tables.html">3D models from tables</a>
</li>
<li>
<a href="../articles/mosaics.html">Mosaics with brickr</a>
</li>

View File

@@ -72,7 +72,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">brickr</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9011</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9014</span>
</span>
</div>
@@ -97,6 +97,15 @@
<li>
<a href="../articles/graphs.html">ggplot with brickr</a>
</li>
<li>
<a href="../articles/models-from-other.html">3D Models from mosaics &amp; rayshader</a>
</li>
<li>
<a href="../articles/models-from-program.html">3D Models programmatically</a>
</li>
<li>
<a href="../articles/models-from-tables.html">3D models from tables</a>
</li>
<li>
<a href="../articles/mosaics.html">Mosaics with brickr</a>
</li>

View File

@@ -72,7 +72,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">brickr</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9011</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9014</span>
</span>
</div>
@@ -97,6 +97,15 @@
<li>
<a href="../articles/graphs.html">ggplot with brickr</a>
</li>
<li>
<a href="../articles/models-from-other.html">3D Models from mosaics &amp; rayshader</a>
</li>
<li>
<a href="../articles/models-from-program.html">3D Models programmatically</a>
</li>
<li>
<a href="../articles/models-from-tables.html">3D models from tables</a>
</li>
<li>
<a href="../articles/mosaics.html">Mosaics with brickr</a>
</li>

View File

@@ -72,7 +72,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">brickr</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9011</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9014</span>
</span>
</div>
@@ -97,6 +97,15 @@
<li>
<a href="../articles/graphs.html">ggplot with brickr</a>
</li>
<li>
<a href="../articles/models-from-other.html">3D Models from mosaics &amp; rayshader</a>
</li>
<li>
<a href="../articles/models-from-program.html">3D Models programmatically</a>
</li>
<li>
<a href="../articles/models-from-tables.html">3D models from tables</a>
</li>
<li>
<a href="../articles/mosaics.html">Mosaics with brickr</a>
</li>

View File

@@ -72,7 +72,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">brickr</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9011</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9014</span>
</span>
</div>
@@ -97,6 +97,15 @@
<li>
<a href="../articles/graphs.html">ggplot with brickr</a>
</li>
<li>
<a href="../articles/models-from-other.html">3D Models from mosaics &amp; rayshader</a>
</li>
<li>
<a href="../articles/models-from-program.html">3D Models programmatically</a>
</li>
<li>
<a href="../articles/models-from-tables.html">3D models from tables</a>
</li>
<li>
<a href="../articles/mosaics.html">Mosaics with brickr</a>
</li>

View File

@@ -72,7 +72,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">brickr</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9011</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9014</span>
</span>
</div>
@@ -97,6 +97,15 @@
<li>
<a href="../articles/graphs.html">ggplot with brickr</a>
</li>
<li>
<a href="../articles/models-from-other.html">3D Models from mosaics &amp; rayshader</a>
</li>
<li>
<a href="../articles/models-from-program.html">3D Models programmatically</a>
</li>
<li>
<a href="../articles/models-from-tables.html">3D models from tables</a>
</li>
<li>
<a href="../articles/mosaics.html">Mosaics with brickr</a>
</li>

View File

@@ -72,7 +72,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">brickr</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9011</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9014</span>
</span>
</div>
@@ -97,6 +97,15 @@
<li>
<a href="../articles/graphs.html">ggplot with brickr</a>
</li>
<li>
<a href="../articles/models-from-other.html">3D Models from mosaics &amp; rayshader</a>
</li>
<li>
<a href="../articles/models-from-program.html">3D Models programmatically</a>
</li>
<li>
<a href="../articles/models-from-tables.html">3D models from tables</a>
</li>
<li>
<a href="../articles/mosaics.html">Mosaics with brickr</a>
</li>

View File

@@ -72,7 +72,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">brickr</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9011</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9014</span>
</span>
</div>
@@ -97,6 +97,15 @@
<li>
<a href="../articles/graphs.html">ggplot with brickr</a>
</li>
<li>
<a href="../articles/models-from-other.html">3D Models from mosaics &amp; rayshader</a>
</li>
<li>
<a href="../articles/models-from-program.html">3D Models programmatically</a>
</li>
<li>
<a href="../articles/models-from-tables.html">3D models from tables</a>
</li>
<li>
<a href="../articles/mosaics.html">Mosaics with brickr</a>
</li>
@@ -154,7 +163,8 @@
<h2 class="hasAnchor" id="see-also"><a class="anchor" href="#see-also"></a>See also</h2>
<div class='dont-index'><p>Other Resources: <code><a href='build_pieces_table.html'>build_pieces_table</a></code>,
<div class='dont-index'><p>Other Resources: <code><a href='build_instructions.html'>build_instructions</a></code>,
<code><a href='build_pieces_table.html'>build_pieces_table</a></code>,
<code><a href='build_pieces.html'>build_pieces</a></code>, <code><a href='build_themes.html'>build_themes</a></code></p></div>

View File

@@ -72,7 +72,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">brickr</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9011</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9014</span>
</span>
</div>
@@ -97,6 +97,15 @@
<li>
<a href="../articles/graphs.html">ggplot with brickr</a>
</li>
<li>
<a href="../articles/models-from-other.html">3D Models from mosaics &amp; rayshader</a>
</li>
<li>
<a href="../articles/models-from-program.html">3D Models programmatically</a>
</li>
<li>
<a href="../articles/models-from-tables.html">3D models from tables</a>
</li>
<li>
<a href="../articles/mosaics.html">Mosaics with brickr</a>
</li>
@@ -127,7 +136,7 @@
<div class="col-md-9 contents">
<div class="page-header">
<h1>Create instruction manual for 2D image mosaics</h1>
<small class="dont-index">Source: <a href='https://github.com/ryantimpe/brickr/blob/master/R/build-mosaic.R'><code>R/build-mosaic.R</code></a></small>
<small class="dont-index">Source: <a href='https://github.com/ryantimpe/brickr/blob/master/R/build-instructions.R'><code>R/build-instructions.R</code></a></small>
<div class="hidden name"><code>build_instructions.Rd</code></div>
</div>
@@ -137,25 +146,26 @@
</div>
<pre class="usage"><span class='fu'>build_instructions</span>(<span class='no'>image_list</span>, <span class='kw'>num_steps</span> <span class='kw'>=</span> <span class='fl'>6</span>)</pre>
<pre class="usage"><span class='fu'>build_instructions</span>(<span class='no'>brickr_obj</span>, <span class='kw'>num_steps</span> <span class='kw'>=</span> <span class='fl'>6</span>)</pre>
<h2 class="hasAnchor" id="arguments"><a class="anchor" href="#arguments"></a>Arguments</h2>
<table class="ref-arguments">
<colgroup><col class="name" /><col class="desc" /></colgroup>
<tr>
<th>image_list</th>
<td><p>Mosaic object from image_to_mosaic().</p></td>
<th>brickr_obj</th>
<td><p>brickr mosaic or 3D model object.</p></td>
</tr>
<tr>
<th>num_steps</th>
<td><p>Number of discrete steps in instruction manual</p></td>
<td><p>Number of discrete steps in instruction manual, for mosaics only</p></td>
</tr>
</table>
<h2 class="hasAnchor" id="see-also"><a class="anchor" href="#see-also"></a>See also</h2>
<div class='dont-index'><p>Other Mosaics: <code><a href='build_mosaic.html'>build_mosaic</a></code>,
<code><a href='image_to_mosaic.html'>image_to_mosaic</a></code></p></div>
<div class='dont-index'><p>Other Resources: <code><a href='build_colors.html'>build_colors</a></code>,
<code><a href='build_pieces_table.html'>build_pieces_table</a></code>,
<code><a href='build_pieces.html'>build_pieces</a></code>, <code><a href='build_themes.html'>build_themes</a></code></p></div>
</div>

View File

@@ -72,7 +72,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">brickr</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9011</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9014</span>
</span>
</div>
@@ -97,6 +97,15 @@
<li>
<a href="../articles/graphs.html">ggplot with brickr</a>
</li>
<li>
<a href="../articles/models-from-other.html">3D Models from mosaics &amp; rayshader</a>
</li>
<li>
<a href="../articles/models-from-program.html">3D Models programmatically</a>
</li>
<li>
<a href="../articles/models-from-tables.html">3D models from tables</a>
</li>
<li>
<a href="../articles/mosaics.html">Mosaics with brickr</a>
</li>
@@ -137,14 +146,14 @@
</div>
<pre class="usage"><span class='fu'>build_mosaic</span>(<span class='no'>image_list</span>, <span class='kw'>title</span> <span class='kw'>=</span> <span class='kw'>NULL</span>)</pre>
<pre class="usage"><span class='fu'>build_mosaic</span>(<span class='no'>brick_obj</span>, <span class='kw'>title</span> <span class='kw'>=</span> <span class='kw'>NULL</span>)</pre>
<h2 class="hasAnchor" id="arguments"><a class="anchor" href="#arguments"></a>Arguments</h2>
<table class="ref-arguments">
<colgroup><col class="name" /><col class="desc" /></colgroup>
<tr>
<th>image_list</th>
<td><p>List output from collect_bricks() or image_to_bricks(). Contains an element <code>Img_lego</code>.</p></td>
<th>brick_obj</th>
<td><p>List output from image_to_bricks(). Contains an element <code>Img_lego</code>.</p></td>
</tr>
<tr>
<th>title</th>
@@ -154,8 +163,7 @@
<h2 class="hasAnchor" id="see-also"><a class="anchor" href="#see-also"></a>See also</h2>
<div class='dont-index'><p>Other Mosaics: <code><a href='build_instructions.html'>build_instructions</a></code>,
<code><a href='image_to_mosaic.html'>image_to_mosaic</a></code></p></div>
<div class='dont-index'><p>Other Mosaics: <code><a href='image_to_mosaic.html'>image_to_mosaic</a></code></p></div>
</div>

View File

@@ -6,7 +6,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Graphically display required bricks. — build_pieces • brickr</title>
<title>Display bricks required to build model or mosaic. — build_pieces • brickr</title>
<!-- favicons -->
<link rel="icon" type="image/png" sizes="16x16" href="../favicon-16x16.png">
@@ -37,9 +37,9 @@
<meta property="og:title" content="Graphically display required bricks. — build_pieces" />
<meta property="og:title" content="Display bricks required to build model or mosaic. — build_pieces" />
<meta property="og:description" content="Graphically display required bricks." />
<meta property="og:description" content="Display bricks required to build model or mosaic." />
<meta property="og:image" content="http://brickr.org/logo.png" />
<meta name="twitter:card" content="summary" />
@@ -72,7 +72,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">brickr</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9011</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9014</span>
</span>
</div>
@@ -97,6 +97,15 @@
<li>
<a href="../articles/graphs.html">ggplot with brickr</a>
</li>
<li>
<a href="../articles/models-from-other.html">3D Models from mosaics &amp; rayshader</a>
</li>
<li>
<a href="../articles/models-from-program.html">3D Models programmatically</a>
</li>
<li>
<a href="../articles/models-from-tables.html">3D models from tables</a>
</li>
<li>
<a href="../articles/mosaics.html">Mosaics with brickr</a>
</li>
@@ -126,25 +135,25 @@
<div class="row">
<div class="col-md-9 contents">
<div class="page-header">
<h1>Graphically display required bricks.</h1>
<h1>Display bricks required to build model or mosaic.</h1>
<small class="dont-index">Source: <a href='https://github.com/ryantimpe/brickr/blob/master/R/piece-count.R'><code>R/piece-count.R</code></a></small>
<div class="hidden name"><code>build_pieces.Rd</code></div>
</div>
<div class="ref-description">
<p>Graphically display required bricks.</p>
<p>Display bricks required to build model or mosaic.</p>
</div>
<pre class="usage"><span class='fu'>build_pieces</span>(<span class='no'>image_list</span>)</pre>
<pre class="usage"><span class='fu'>build_pieces</span>(<span class='no'>brick_obj</span>)</pre>
<h2 class="hasAnchor" id="arguments"><a class="anchor" href="#arguments"></a>Arguments</h2>
<table class="ref-arguments">
<colgroup><col class="name" /><col class="desc" /></colgroup>
<tr>
<th>image_list</th>
<td><p>Mosaic output from image_to_mosaic().</p></td>
<th>brick_obj</th>
<td><p>brickr mosaic or 3D model object.</p></td>
</tr>
</table>
@@ -155,6 +164,7 @@
<h2 class="hasAnchor" id="see-also"><a class="anchor" href="#see-also"></a>See also</h2>
<div class='dont-index'><p>Other Resources: <code><a href='build_colors.html'>build_colors</a></code>,
<code><a href='build_instructions.html'>build_instructions</a></code>,
<code><a href='build_pieces_table.html'>build_pieces_table</a></code>,
<code><a href='build_themes.html'>build_themes</a></code></p></div>

View File

@@ -72,7 +72,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">brickr</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9011</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9014</span>
</span>
</div>
@@ -97,6 +97,15 @@
<li>
<a href="../articles/graphs.html">ggplot with brickr</a>
</li>
<li>
<a href="../articles/models-from-other.html">3D Models from mosaics &amp; rayshader</a>
</li>
<li>
<a href="../articles/models-from-program.html">3D Models programmatically</a>
</li>
<li>
<a href="../articles/models-from-tables.html">3D models from tables</a>
</li>
<li>
<a href="../articles/mosaics.html">Mosaics with brickr</a>
</li>
@@ -137,14 +146,14 @@
</div>
<pre class="usage"><span class='fu'>build_pieces_table</span>(<span class='no'>image_list</span>)</pre>
<pre class="usage"><span class='fu'>build_pieces_table</span>(<span class='no'>brick_obj</span>)</pre>
<h2 class="hasAnchor" id="arguments"><a class="anchor" href="#arguments"></a>Arguments</h2>
<table class="ref-arguments">
<colgroup><col class="name" /><col class="desc" /></colgroup>
<tr>
<th>image_list</th>
<td><p>Mosaic output from image_to_mosaic().</p></td>
<th>brick_obj</th>
<td><p>brickr mosaic or 3D model object.</p></td>
</tr>
</table>
@@ -155,6 +164,7 @@
<h2 class="hasAnchor" id="see-also"><a class="anchor" href="#see-also"></a>See also</h2>
<div class='dont-index'><p>Other Resources: <code><a href='build_colors.html'>build_colors</a></code>,
<code><a href='build_instructions.html'>build_instructions</a></code>,
<code><a href='build_pieces.html'>build_pieces</a></code>, <code><a href='build_themes.html'>build_themes</a></code></p></div>

View File

@@ -72,7 +72,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">brickr</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9011</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9014</span>
</span>
</div>
@@ -97,6 +97,15 @@
<li>
<a href="../articles/graphs.html">ggplot with brickr</a>
</li>
<li>
<a href="../articles/models-from-other.html">3D Models from mosaics &amp; rayshader</a>
</li>
<li>
<a href="../articles/models-from-program.html">3D Models programmatically</a>
</li>
<li>
<a href="../articles/models-from-tables.html">3D models from tables</a>
</li>
<li>
<a href="../articles/mosaics.html">Mosaics with brickr</a>
</li>
@@ -159,6 +168,7 @@
<h2 class="hasAnchor" id="see-also"><a class="anchor" href="#see-also"></a>See also</h2>
<div class='dont-index'><p>Other Resources: <code><a href='build_colors.html'>build_colors</a></code>,
<code><a href='build_instructions.html'>build_instructions</a></code>,
<code><a href='build_pieces_table.html'>build_pieces_table</a></code>,
<code><a href='build_pieces.html'>build_pieces</a></code></p></div>

View File

@@ -72,7 +72,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">brickr</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9011</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9014</span>
</span>
</div>
@@ -97,6 +97,15 @@
<li>
<a href="../articles/graphs.html">ggplot with brickr</a>
</li>
<li>
<a href="../articles/models-from-other.html">3D Models from mosaics &amp; rayshader</a>
</li>
<li>
<a href="../articles/models-from-program.html">3D Models programmatically</a>
</li>
<li>
<a href="../articles/models-from-tables.html">3D models from tables</a>
</li>
<li>
<a href="../articles/mosaics.html">Mosaics with brickr</a>
</li>

View File

@@ -73,7 +73,7 @@ Use coord_brick_flip() for horizontal bars." />
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">brickr</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9011</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9014</span>
</span>
</div>
@@ -98,6 +98,15 @@ Use coord_brick_flip() for horizontal bars." />
<li>
<a href="../articles/graphs.html">ggplot with brickr</a>
</li>
<li>
<a href="../articles/models-from-other.html">3D Models from mosaics &amp; rayshader</a>
</li>
<li>
<a href="../articles/models-from-program.html">3D Models programmatically</a>
</li>
<li>
<a href="../articles/models-from-tables.html">3D models from tables</a>
</li>
<li>
<a href="../articles/mosaics.html">Mosaics with brickr</a>
</li>

View File

@@ -73,7 +73,7 @@ Bar height is determined by values in the data using the y aesthetic. With the e
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">brickr</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9011</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9014</span>
</span>
</div>
@@ -98,6 +98,15 @@ Bar height is determined by values in the data using the y aesthetic. With the e
<li>
<a href="../articles/graphs.html">ggplot with brickr</a>
</li>
<li>
<a href="../articles/models-from-other.html">3D Models from mosaics &amp; rayshader</a>
</li>
<li>
<a href="../articles/models-from-program.html">3D Models programmatically</a>
</li>
<li>
<a href="../articles/models-from-tables.html">3D models from tables</a>
</li>
<li>
<a href="../articles/mosaics.html">Mosaics with brickr</a>
</li>

View File

@@ -72,7 +72,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">brickr</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9011</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9014</span>
</span>
</div>
@@ -97,6 +97,15 @@
<li>
<a href="../articles/graphs.html">ggplot with brickr</a>
</li>
<li>
<a href="../articles/models-from-other.html">3D Models from mosaics &amp; rayshader</a>
</li>
<li>
<a href="../articles/models-from-program.html">3D Models programmatically</a>
</li>
<li>
<a href="../articles/models-from-tables.html">3D models from tables</a>
</li>
<li>
<a href="../articles/mosaics.html">Mosaics with brickr</a>
</li>

View File

@@ -72,7 +72,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">brickr</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9011</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9014</span>
</span>
</div>
@@ -97,6 +97,15 @@
<li>
<a href="../articles/graphs.html">ggplot with brickr</a>
</li>
<li>
<a href="../articles/models-from-other.html">3D Models from mosaics &amp; rayshader</a>
</li>
<li>
<a href="../articles/models-from-program.html">3D Models programmatically</a>
</li>
<li>
<a href="../articles/models-from-tables.html">3D models from tables</a>
</li>
<li>
<a href="../articles/mosaics.html">Mosaics with brickr</a>
</li>
@@ -198,8 +207,7 @@ Use "bw" for only grayscale bricks. Ignored if a <code>color_table</code> is sup
<h2 class="hasAnchor" id="see-also"><a class="anchor" href="#see-also"></a>See also</h2>
<div class='dont-index'><p>Other Mosaics: <code><a href='build_instructions.html'>build_instructions</a></code>,
<code><a href='build_mosaic.html'>build_mosaic</a></code></p></div>
<div class='dont-index'><p>Other Mosaics: <code><a href='build_mosaic.html'>build_mosaic</a></code></p></div>
</div>

View File

@@ -72,7 +72,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">brickr</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9011</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9014</span>
</span>
</div>
@@ -97,6 +97,15 @@
<li>
<a href="../articles/graphs.html">ggplot with brickr</a>
</li>
<li>
<a href="../articles/models-from-other.html">3D Models from mosaics &amp; rayshader</a>
</li>
<li>
<a href="../articles/models-from-program.html">3D Models programmatically</a>
</li>
<li>
<a href="../articles/models-from-tables.html">3D models from tables</a>
</li>
<li>
<a href="../articles/mosaics.html">Mosaics with brickr</a>
</li>

View File

@@ -70,7 +70,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">brickr</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9011</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9014</span>
</span>
</div>
@@ -95,6 +95,15 @@
<li>
<a href="../articles/graphs.html">ggplot with brickr</a>
</li>
<li>
<a href="../articles/models-from-other.html">3D Models from mosaics &amp; rayshader</a>
</li>
<li>
<a href="../articles/models-from-program.html">3D Models programmatically</a>
</li>
<li>
<a href="../articles/models-from-tables.html">3D models from tables</a>
</li>
<li>
<a href="../articles/mosaics.html">Mosaics with brickr</a>
</li>
@@ -261,7 +270,7 @@
<td>
<p><code><a href="build_pieces.html">build_pieces()</a></code> </p>
</td>
<td><p>Graphically display required bricks.</p></td>
<td><p>Display bricks required to build model or mosaic.</p></td>
</tr><tr>
<td>

View File

@@ -72,7 +72,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">brickr</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9011</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9014</span>
</span>
</div>
@@ -97,6 +97,15 @@
<li>
<a href="../articles/graphs.html">ggplot with brickr</a>
</li>
<li>
<a href="../articles/models-from-other.html">3D Models from mosaics &amp; rayshader</a>
</li>
<li>
<a href="../articles/models-from-program.html">3D Models programmatically</a>
</li>
<li>
<a href="../articles/models-from-tables.html">3D models from tables</a>
</li>
<li>
<a href="../articles/mosaics.html">Mosaics with brickr</a>
</li>

View File

@@ -72,7 +72,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">brickr</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9011</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9014</span>
</span>
</div>
@@ -97,6 +97,15 @@
<li>
<a href="../articles/graphs.html">ggplot with brickr</a>
</li>
<li>
<a href="../articles/models-from-other.html">3D Models from mosaics &amp; rayshader</a>
</li>
<li>
<a href="../articles/models-from-program.html">3D Models programmatically</a>
</li>
<li>
<a href="../articles/models-from-tables.html">3D models from tables</a>
</li>
<li>
<a href="../articles/mosaics.html">Mosaics with brickr</a>
</li>

View File

@@ -72,7 +72,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">brickr</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9011</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9014</span>
</span>
</div>
@@ -97,6 +97,15 @@
<li>
<a href="../articles/graphs.html">ggplot with brickr</a>
</li>
<li>
<a href="../articles/models-from-other.html">3D Models from mosaics &amp; rayshader</a>
</li>
<li>
<a href="../articles/models-from-program.html">3D Models programmatically</a>
</li>
<li>
<a href="../articles/models-from-tables.html">3D models from tables</a>
</li>
<li>
<a href="../articles/mosaics.html">Mosaics with brickr</a>
</li>

View File

@@ -72,7 +72,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">brickr</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9011</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9014</span>
</span>
</div>
@@ -97,6 +97,15 @@
<li>
<a href="../articles/graphs.html">ggplot with brickr</a>
</li>
<li>
<a href="../articles/models-from-other.html">3D Models from mosaics &amp; rayshader</a>
</li>
<li>
<a href="../articles/models-from-program.html">3D Models programmatically</a>
</li>
<li>
<a href="../articles/models-from-tables.html">3D models from tables</a>
</li>
<li>
<a href="../articles/mosaics.html">Mosaics with brickr</a>
</li>

View File

@@ -72,7 +72,7 @@
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">brickr</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9011</span>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.1.0.9014</span>
</span>
</div>
@@ -97,6 +97,15 @@
<li>
<a href="../articles/graphs.html">ggplot with brickr</a>
</li>
<li>
<a href="../articles/models-from-other.html">3D Models from mosaics &amp; rayshader</a>
</li>
<li>
<a href="../articles/models-from-program.html">3D Models programmatically</a>
</li>
<li>
<a href="../articles/models-from-tables.html">3D models from tables</a>
</li>
<li>
<a href="../articles/mosaics.html">Mosaics with brickr</a>
</li>

View File

@@ -78,6 +78,15 @@
<url>
<loc>http://brickr.org/articles/graphs.html</loc>
</url>
<url>
<loc>http://brickr.org/articles/models-from-other.html</loc>
</url>
<url>
<loc>http://brickr.org/articles/models-from-program.html</loc>
</url>
<url>
<loc>http://brickr.org/articles/models-from-tables.html</loc>
</url>
<url>
<loc>http://brickr.org/articles/mosaics.html</loc>
</url>

View File

@@ -23,7 +23,8 @@ build_colors()
build_colors(TRUE)
}
\seealso{
Other Resources: \code{\link{build_pieces_table}},
Other Resources: \code{\link{build_instructions}},
\code{\link{build_pieces_table}},
\code{\link{build_pieces}}, \code{\link{build_themes}}
}
\concept{Resources}

View File

@@ -1,21 +1,22 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/build-mosaic.R
% Please edit documentation in R/build-instructions.R
\name{build_instructions}
\alias{build_instructions}
\title{Create instruction manual for 2D image mosaics}
\usage{
build_instructions(image_list, num_steps = 6)
build_instructions(brickr_obj, num_steps = 6)
}
\arguments{
\item{image_list}{Mosaic object from image_to_mosaic().}
\item{brickr_obj}{brickr mosaic or 3D model object.}
\item{num_steps}{Number of discrete steps in instruction manual}
\item{num_steps}{Number of discrete steps in instruction manual, for mosaics only}
}
\description{
Create instruction manual for 2D image mosaics
}
\seealso{
Other Mosaics: \code{\link{build_mosaic}},
\code{\link{image_to_mosaic}}
Other Resources: \code{\link{build_colors}},
\code{\link{build_pieces_table}},
\code{\link{build_pieces}}, \code{\link{build_themes}}
}
\concept{Mosaics}
\concept{Resources}

View File

@@ -4,10 +4,10 @@
\alias{build_mosaic}
\title{Display 2D LEGO mosaic as a plot image}
\usage{
build_mosaic(image_list, title = NULL)
build_mosaic(brick_obj, title = NULL)
}
\arguments{
\item{image_list}{List output from collect_bricks() or image_to_bricks(). Contains an element \code{Img_lego}.}
\item{brick_obj}{List output from image_to_bricks(). Contains an element \code{Img_lego}.}
\item{title}{Optional title to include above plotted mosaic.}
}
@@ -15,7 +15,6 @@ build_mosaic(image_list, title = NULL)
Display 2D LEGO mosaic as a plot image
}
\seealso{
Other Mosaics: \code{\link{build_instructions}},
\code{\link{image_to_mosaic}}
Other Mosaics: \code{\link{image_to_mosaic}}
}
\concept{Mosaics}

View File

@@ -2,21 +2,22 @@
% Please edit documentation in R/piece-count.R
\name{build_pieces}
\alias{build_pieces}
\title{Graphically display required bricks.}
\title{Display bricks required to build model or mosaic.}
\usage{
build_pieces(image_list)
build_pieces(brick_obj)
}
\arguments{
\item{image_list}{Mosaic output from image_to_mosaic().}
\item{brick_obj}{brickr mosaic or 3D model object.}
}
\value{
Plot object of required bricks by color and size.
}
\description{
Graphically display required bricks.
Display bricks required to build model or mosaic.
}
\seealso{
Other Resources: \code{\link{build_colors}},
\code{\link{build_instructions}},
\code{\link{build_pieces_table}},
\code{\link{build_themes}}
}

View File

@@ -4,10 +4,10 @@
\alias{build_pieces_table}
\title{Generate required bricks as a data frame.}
\usage{
build_pieces_table(image_list)
build_pieces_table(brick_obj)
}
\arguments{
\item{image_list}{Mosaic output from image_to_mosaic().}
\item{brick_obj}{brickr mosaic or 3D model object.}
}
\value{
Data frame of piece counts by LEGO color name and size.
@@ -17,6 +17,7 @@ Generate required bricks as a data frame.
}
\seealso{
Other Resources: \code{\link{build_colors}},
\code{\link{build_instructions}},
\code{\link{build_pieces}}, \code{\link{build_themes}}
}
\concept{Resources}

View File

@@ -27,6 +27,7 @@ build_themes(.names_only = TRUE)
}
\seealso{
Other Resources: \code{\link{build_colors}},
\code{\link{build_instructions}},
\code{\link{build_pieces_table}},
\code{\link{build_pieces}}
}

View File

@@ -42,7 +42,6 @@ A list with element \code{Img_lego} containing a data frame of the x- & y-coordi
Create a 2D LEGO mosaic from an image array
}
\seealso{
Other Mosaics: \code{\link{build_instructions}},
\code{\link{build_mosaic}}
Other Mosaics: \code{\link{build_mosaic}}
}
\concept{Mosaics}

BIN
vignettes/dem_01.tif Normal file

Binary file not shown.

View File

@@ -0,0 +1,89 @@
---
title: "3D Models from mosaics & rayshader"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{graphs}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```
```{r setup, include = FALSE}
library(brickr)
```
## Getting started
The `bricks_from_*` series of functions creates 3D models of LEGO bricks from a variety of input formats. These models are rendered using [Tyler Morgan-Wall](https://twitter.com/tylermorganwall)'s [rayshader](https://www.rayshader.com/) package. This package must be installed.
## 3D mosaics
Begin with a brickr mosaic from an image. Rather than graphically rendering the mosaic using `build_mosaic()`, use `bricks_from_mosaic()`. This function takes two other inputs:
* `mosaic_height` is the number of bricks stacked at the mosaic's highest point. The default is 6.
* `highest_el` specifies if 'light' or 'dark' color bricks should be the tallest in the model. The default is 'light'.
```{r bricks_6, echo=TRUE, warning=FALSE, message=FALSE, fig.width=4, fig.height=4}
mosaic <- png::readPNG("../Images/mf_unicorn.PNG") %>%
image_to_mosaic()
mosaic %>% build_mosaic()
mosaic %>%
bricks_from_mosaic(highest_el = "dark") %>%
build_bricks(phi = 60, theta = 15)
rayshader::render_snapshot(clear = TRUE)
```
## Models from rayshader
[rayshader](https://www.rayshader.com/) by [Tyler Morgan-Wall](https://twitter.com/tylermorganwall) is an open source package for producing 2D and 3D data visualizations in R. rayshader uses elevation data in a base R matrix and a combination of raytracing, spherical texture mapping, overlays, and ambient occlusion to generate beautiful topographic 2D and 3D maps. (Note: text lifted straight from [rayshader.com](https://www.rayshader.com/).)
3D models in **brickr** are rendered using the functions in **rayshader**. Using `bricks_from_rayshader()`, you can convert rayshader map output into a brickr model. This function takes three inputs:
* `hillshade` is topographic image matrix with an RGB channel (much like the mosaics).
* `heightmap` is a two-dimensional matrix specifiying the height of the image at each location.
* `max_height` is the number of bricks stacked at the mosaic's highest point. The default is 12.
* `img_size` is the number of bricks on each side of the model. The default is 48.
```{r bricks_rayshader, echo=TRUE, warning=FALSE, message=FALSE, fig.width=4, fig.height=4}
library(rayshader)
#Example from rayshader.com
#Here, I load a map with the raster package.
loadzip = tempfile()
download.file("https://tylermw.com/data/dem_01.tif.zip", loadzip)
localtif = raster::raster(unzip(loadzip, "dem_01.tif"))
unlink(loadzip)
#And convert it to a matrix:
elmat = matrix(raster::extract(localtif, raster::extent(localtif), buffer = 1000),
nrow = ncol(localtif), ncol = nrow(localtif))
rayshader_object <- elmat %>%
sphere_shade(texture = "desert") %>%
add_water(detect_water(elmat), color = "desert") %>%
add_shadow(ray_shade(elmat, zscale = 3, maxsearch = 300), 0.5)
#Plot with rayshader
rayshader_object %>%
plot_3d(elmat, zscale = 10, fov = 0, theta = 135, zoom = 0.75, phi = 45, windowsize = c(1000, 800))
rayshader::render_snapshot(clear = TRUE)
#Plot as bricks
rayshader_object %>%
bricks_from_rayshader(elmat) %>%
build_bricks(theta = 135, zoom = 0.75, phi = 45)
rayshader::render_snapshot(clear = TRUE)
```

View File

@@ -0,0 +1,148 @@
---
title: "3D Models programmatically"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{graphs}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```
```{r setup, include = FALSE}
library(brickr)
```
## Getting started
The `bricks_from_*` series of functions creates 3D models of LEGO bricks from a variety of input formats. These models are rendered using [Tyler Morgan-Wall](https://twitter.com/tylermorganwall)'s [rayshader](https://www.rayshader.com/) package. This package must be installed.
Use `bricks_from_coords()` to programmatically build 3D LEGO models rather than manually drawing them in a spreadsheet or table. Prove the function with a data frame with x, y, and z coordinates, along with an official LEGO color name for each point.
## A simple programmed model
Below, we create a 8x8x8 cube by expanding a data frame with the array 1:8 as the x-, y-, and z-coordinates. We then assign each row of that data frame one of three colors: Bright blue, Bright yellow, or Bright red.
```{r bricks_6, echo=TRUE, warning=FALSE, message=FALSE, fig.width=4, fig.height=4}
use_colors <- c("Bright blue", "Bright yellow", "Bright red")
cube <- expand.grid(
x = 1:8,
y = 1:8,
z = 1:8
)
cube$Color <- sample(use_colors, nrow(cube), replace = TRUE, prob = c(5, 3, 1))
cube %>%
bricks_from_coords() %>%
build_bricks(brick_res = "hd", phi = 30, theta = 30)
rayshader::render_snapshot(clear = TRUE)
```
Using the same logic, we can build a sphere with a specified radius, and then apply rules to color each brick based on its coordinates.
```{r bricks_7, echo=TRUE, warning=FALSE, message=FALSE, fig.width=4, fig.height=4}
radius <- 4
sphere_coords <- expand.grid(
x = 1:round((radius*2.5)),
y = 1:round((radius*2.5)),
z = 1:round((radius/(6/5)*2.5)) #A brick is 6/5 taller than it is wide/deep
) %>%
dplyr::mutate(
#Distance of each coordinate from center
dist = (((x-mean(x))^2 + (y-mean(y))^2 + (z-mean(z))^2)^(1/2)),
Color = dplyr::case_when(
#Yellow stripes on the surface with a 2to4 thickness
dplyr::between(dist, (radius-1), radius) & (x+y+z) %% 6 %in% 0:1 ~ "Bright yellow",
#Otherwise, sphere is blue
dist <= radius ~ "Bright blue"
))
sphere_coords %>%
bricks_from_coords() %>%
build_bricks(brick_res = "hd", phi = 30, theta = 30)
rayshader::render_snapshot(clear = TRUE)
```
## It takes a village
Rather than directly writing a data frame for a model, you can write a function that returns a data frame with x, y, z, and Color coordinates given initial starting parameters.
Below, the function `brick_house()` creates a LEGO house with randomized colors. The x- and y-coordinates and the size of the house are inputs to the functions.
```{r bricks_8, echo=TRUE, warning=FALSE, message=FALSE, fig.width=4, fig.height=4}
brick_house <- function(x_coord = 0, y_coord = 0, width=6, length=5, height=6){
roof_colors <- c("Dark orange", "Dark brown", "Medium nougat", "Medium stone grey")
roof_col <- sample(roof_colors, 1)
house_colors <- c("Bright blue", "Bright red", "Dark red", "Dark azur", "Nougat", "Bright reddish violet")
house_col <- sample(house_colors, 1)
house_coords <- expand.grid(
x = 1:width, y = 1:length, z = (1:height)+1
) %>%
dplyr::mutate(
roof = (z > round((1/2)*height)),
Color = dplyr::case_when(
#Roof
roof & (abs(y - floor(length/2) -1) <= (height-z)) ~ roof_col,
roof ~ NA_character_,
#Door and windows
x == round(width/2) & z == 1 ~ NA_character_,
dplyr::between(x, 2, width-1) & x %% 2 == 0 & y > 1 & z == 2 ~ NA_character_,
dplyr::between(y, 2, length-1) & y %% 2 == 0 & z == 2 ~ NA_character_,
x %in% c(1, width) | y %in% c(1, length) ~ house_col),
x = x+x_coord,
y = y+y_coord
)
return(house_coords)
}
#Build one house
brick_house() %>% bricks_from_coords() %>%
build_bricks(theta = 225)
rayshader::render_snapshot(clear = TRUE)
```
Next, we write one more function, `brick_street()` to build a road and grass foundation. The, for an arbitrary number of houses and neighborhood size, use `purrr::pmap_df` to generate many houses and place them along the road.
```{r bricks_9, echo=TRUE, warning=FALSE, message=FALSE, fig.width=4, fig.height=4}
brick_street <- function(width = 100, length = 40){
expand.grid(x=1:width, y=1:length, z=1) %>%
dplyr::mutate(
Color = dplyr::case_when(
y == round(length/2) & x %% 4 %in% 1:4 ~ "Bright yellow",
dplyr::between(y, length/2 -5, length/2 +5) ~ "Dark stone grey",
TRUE ~ "Dark green"
))
}
#Build a village, houses on 2 sides of a street
n_houses = 14
sz = c(100, 40)
list(x_coord = c(sample(seq(10, sz[1]-10, by = 10), n_houses/2),
sample(seq(10, sz[1]-10, by = 10), n_houses/2)),
y_coord = c(rep(sz[2]/2-15, n_houses/2), rep(sz[2]/2+10, n_houses/2)),
width = sample(4:10, n_houses, replace = TRUE),
length = sample(4:8, n_houses, replace = TRUE),
height = sample(5:8, n_houses, replace = TRUE)
) %>%
purrr::pmap_df(brick_house) %>%
dplyr::bind_rows(brick_street(sz[1], sz[2])) %>%
bricks_from_coords() %>%
build_bricks()
rayshader::render_camera(theta = 60, phi = 20, zoom = 0.75)
rayshader::render_snapshot(clear = TRUE)
```