mirror of
https://github.com/ryantimpe/brickr.git
synced 2026-02-18 04:40:05 -06:00
The rest of the 0.3.2 cran edits
This commit is contained in:
@@ -14,7 +14,8 @@ if(getRversion() >= "2.15.1") {
|
||||
"brick_area", "brick_width", "brick_height",
|
||||
"channel", "col2rgb", "color", "Color", "color_hex", "dist",
|
||||
"elevation", "G", "G_lego",
|
||||
"ggproto", "height", "hex", "layer",
|
||||
"ggproto", "height", "hex",
|
||||
"id", "layer",
|
||||
"lego", "Lego_color", "LEGO_color", "lego_colors",
|
||||
"Lego_name", "Level", "lum", "Lum",
|
||||
"median", "mid_level", "n",
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#' Convert a 2D LEGO mosaic into a 'brickr' 3D object
|
||||
#'
|
||||
#' Stacks LEGO plates to create a 3D version of the 2D brick mosaics.
|
||||
#'
|
||||
#' Height of bricks determined by brightness of color.
|
||||
#'
|
||||
#' @param mosaic_list List output from image_to_bricks(). Contains an element \code{Img_lego}.
|
||||
@@ -10,18 +9,37 @@
|
||||
#' @return A list with elements \code{Img_lego} to pass to \code{\link{build_bricks}}.
|
||||
#' @family 3D Models
|
||||
#' @export
|
||||
#' @examples \donttest{
|
||||
#' # Create a random 24x24 'image'.
|
||||
#' # Otherwise, use a jpeg or png
|
||||
#' demo_image = array(scales::rescale(runif(24*24*3), c(0, 1)), dim=c(24, 24, 3))
|
||||
#'
|
||||
#' demo_image %>%
|
||||
#' image_to_mosaic(img_size = 24) %>%
|
||||
#' bricks_from_mosaic() %>%
|
||||
#' build_bricks()
|
||||
#' @examples
|
||||
#' # Import a jpeg or png
|
||||
#' demo_file <- system.file("extdata", "demo_img.jpg",
|
||||
#' package = "brickr", mustWork = TRUE)
|
||||
#' demo_image <- jpeg::readJPEG(demo_file)
|
||||
#'
|
||||
#' rgl::clear3d()
|
||||
#'}
|
||||
#' #Begin with a 24x24 mosaic object
|
||||
#' \donttest{
|
||||
#' mosaic <- demo_image %>%
|
||||
#' image_to_mosaic(24)
|
||||
#' }
|
||||
#'
|
||||
#' #Pass the mosaic object to bricks_from_mosaic() to convert to 3D specifications
|
||||
#' \donttest{
|
||||
#' mosaic %>%
|
||||
#' bricks_from_mosaic() %>%
|
||||
#' build_bricks()
|
||||
#'
|
||||
#' rgl::clear3d()
|
||||
#' }
|
||||
#'
|
||||
#' #In this image, the background is a light color.
|
||||
#' # Change the 'highest_el' to make dark colors highest
|
||||
#' # Change mosaic height to change the number of layers
|
||||
#' \donttest{
|
||||
#' mosaic %>%
|
||||
#' bricks_from_mosaic(mosaic_height = 3, highest_el = "dark") %>%
|
||||
#' build_bricks()
|
||||
#'
|
||||
#' rgl::clear3d()
|
||||
#' }
|
||||
bricks_from_mosaic <- function(mosaic_list, mosaic_height = 6, highest_el = "light"){
|
||||
|
||||
#Get previous data
|
||||
|
||||
@@ -53,11 +53,14 @@
|
||||
#' X1 = c("b", "b", "p", "p"), #b is brick (default), p is plate
|
||||
#' X2 = c("b", "b", "p", "p")
|
||||
#')
|
||||
#'
|
||||
#'\donttest{
|
||||
#'brick %>%
|
||||
#' bricks_from_table(piece_matrix=pieces) %>%
|
||||
#' build_bricks()
|
||||
#'
|
||||
#' rgl::clear3d()
|
||||
#' }
|
||||
#'
|
||||
#' #Provide a custom table of colors
|
||||
#' custom_colors <- data.frame(
|
||||
@@ -65,18 +68,22 @@
|
||||
#' Color = c("Bright orange", "Dark green")
|
||||
#' )
|
||||
#'
|
||||
#' \donttest{
|
||||
#'brick %>%
|
||||
#' bricks_from_table(color_guide = custom_colors) %>%
|
||||
#' build_bricks()
|
||||
#'
|
||||
#' rgl::clear3d()
|
||||
#' }
|
||||
#'
|
||||
#'#Limit the size of bricks used in the model with use_bricks
|
||||
#'\donttest{
|
||||
#'brick %>%
|
||||
#' bricks_from_table(use_bricks = "2x1") %>% #Only use 2x1 bricks.
|
||||
#' build_bricks()
|
||||
#'
|
||||
#' rgl::clear3d()
|
||||
#' }
|
||||
|
||||
bricks_from_table <- function(matrix_table, color_guide = brickr::lego_colors,
|
||||
piece_matrix = NULL,
|
||||
@@ -402,27 +409,31 @@ bricks_from_excel <- function(excel_table,
|
||||
#'
|
||||
#' #This is a lot of bricks
|
||||
#' bricks <- expand.grid(
|
||||
#' x = 1:8,
|
||||
#' y = 1:4,
|
||||
#' x = 1:4,
|
||||
#' y = 1:2,
|
||||
#' z = 1:3)
|
||||
#'
|
||||
#' #Color them in sets of these 3 options
|
||||
#' bricks$color <- rep(rep(c("Bright yellow", "Bright red", "Tr. green"), each=4), 8)
|
||||
#' bricks$color <- rep(rep(c("Bright yellow", "Bright red", "Tr. green"), each=4), 2)
|
||||
#'
|
||||
#' \donttest{
|
||||
#' bricks %>%
|
||||
#' bricks_from_coords() %>%
|
||||
#' build_bricks()
|
||||
#'
|
||||
#' rgl::clear3d()
|
||||
#' }
|
||||
#'
|
||||
#'#Use different brick shapes by added a 'piece_type' column
|
||||
#'bricks$piece_type <- "c1" #Make all the pieces cylinders
|
||||
#'
|
||||
#'\donttest{
|
||||
#'bricks %>%
|
||||
#' bricks_from_coords() %>%
|
||||
#' build_bricks()
|
||||
#'
|
||||
#' rgl::clear3d()
|
||||
#' }
|
||||
#'
|
||||
bricks_from_coords <- function(coord_table,
|
||||
use_bricks = NULL,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#' Build 3D brick model with 'rgl'
|
||||
#'
|
||||
#' Render the output of any of the \code{bricks_from_*} functions as a 3D model.
|
||||
#' Render the output of any of the \code{bricks_from_*} functions as a 3D model. Opens an 'rgl' window.
|
||||
#'
|
||||
#' @param brick_list List output from a \code{bricks_from_*} function. Contains an element \code{Img_lego}.
|
||||
#' @param background_color Default 'white'. Color of the background.
|
||||
@@ -9,7 +9,7 @@
|
||||
#' Set to 'TRUE' and rgl_lit='FALSE' for cartoon-looking bricks.
|
||||
#' @param trans_alpha Default 0.5. Alpha level for transparent bricks.
|
||||
#' @param view_levels Numeric array of Levels/z values to display. Leave as 'NULL' to include all.
|
||||
#' @examples \donttest{
|
||||
#' @examples
|
||||
#' #This is a brick
|
||||
#'brick <- data.frame(
|
||||
#' Level="A",
|
||||
@@ -17,12 +17,23 @@
|
||||
#' X2 = rep(3,4)
|
||||
#')
|
||||
#'
|
||||
#'brick %>%
|
||||
#' bricks_from_table() %>%
|
||||
#' build_bricks()
|
||||
#'#Convert the dataframe to a list object that can be rendered
|
||||
#'brick_object <- brick %>%
|
||||
#' bricks_from_table()
|
||||
#'
|
||||
#'#Render it
|
||||
#'brick_object %>%
|
||||
#' build_bricks()
|
||||
#'
|
||||
#' rgl::clear3d()
|
||||
#'
|
||||
#'#Combine the option rgl_lit=FALSE & outline_bricks=TRUE
|
||||
#'# This makes the rendering look like a drawing
|
||||
#' brick_object %>%
|
||||
#' build_bricks(outline_bricks = TRUE, rgl_lit = FALSE,
|
||||
#' background_color = "#99e7ff")
|
||||
#'rgl::clear3d()
|
||||
#' }
|
||||
#'
|
||||
#' @return 3D brick model rendered in the 'rgl' package.
|
||||
#' @family 3D Models
|
||||
#' @export
|
||||
|
||||
@@ -13,15 +13,29 @@
|
||||
#' @return A single plot object of steps to build brickr model or mosaic.
|
||||
#' @family Resources
|
||||
#' @export
|
||||
#' @examples \donttest{
|
||||
#' # Create a random 24x24 'image'.
|
||||
#' # Otherwise, use a jpeg or png
|
||||
#' demo_image = array(scales::rescale(runif(24*24*3), c(0, 1)), dim=c(24, 24, 3))
|
||||
#'
|
||||
#' demo_image %>%
|
||||
#' image_to_mosaic(img_size = 24) %>%
|
||||
#' build_instructions()
|
||||
#'}
|
||||
#' @examples
|
||||
#' # Import a jpeg or png
|
||||
#' demo_file <- system.file("extdata", "demo_img.jpg",
|
||||
#' package = "brickr", mustWork = TRUE)
|
||||
#' demo_image <- jpeg::readJPEG(demo_file)
|
||||
#'
|
||||
#' #Create a mosaic oject
|
||||
#' \donttest{
|
||||
#' mosaic <- demo_image %>%
|
||||
#' image_to_mosaic(img_size = 24)
|
||||
#' }
|
||||
#'
|
||||
#' #Rather than drawing the mosaic, use build_instructions() to draw instructions
|
||||
#' \donttest{
|
||||
#' mosaic %>%
|
||||
#' build_instructions()
|
||||
#' }
|
||||
#'
|
||||
#' #Change the number of steps for more detail
|
||||
#' \donttest{
|
||||
#' mosaic %>%
|
||||
#' build_instructions(num_steps = 9)
|
||||
#' }
|
||||
#'
|
||||
|
||||
build_instructions <- function(brickr_obj, num_steps=6) {
|
||||
|
||||
@@ -10,11 +10,23 @@
|
||||
#' @examples
|
||||
#'
|
||||
#' # Import a jpeg or png
|
||||
#' demo_image = system.file("extdata", "demo_img.jpg", package = "brickr", mustWork = TRUE)
|
||||
#'
|
||||
#' jpeg::readJPEG(demo_image) %>%
|
||||
#' image_to_mosaic() %>%
|
||||
#' demo_file <- system.file("extdata", "demo_img.jpg",
|
||||
#' package = "brickr", mustWork = TRUE)
|
||||
#' demo_image <- jpeg::readJPEG(demo_file)
|
||||
#'
|
||||
#' #Build a very small 12x12 mosaic.
|
||||
#' \donttest{
|
||||
#' demo_image %>%
|
||||
#' image_to_mosaic(12) %>%
|
||||
#' build_mosaic()
|
||||
#' }
|
||||
#'
|
||||
#' #Build a mosaic in the default size of 48x48 studs with title
|
||||
#' \donttest{
|
||||
#' demo_image %>%
|
||||
#' image_to_mosaic() %>%
|
||||
#' build_mosaic("Demo mosaic")
|
||||
#' }
|
||||
|
||||
build_mosaic <- function(brick_obj, title=NULL){
|
||||
in_list <- brick_obj
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
#' Consolidate 1x1 bricks into larger ones of the same color. Internal function.
|
||||
#' Consolidate 1x1 bricks into larger ones of the same color
|
||||
#'
|
||||
#' Internal function for collecting single bricks into large ones. Used in both mosaics and 3D models.
|
||||
#' Automatically generate missing piece_type or mid_level.
|
||||
#'
|
||||
#' @param image_list List output from legoize(). Contains an element \code{Img_lego}.
|
||||
#' @param image_list List output containing an element \code{Img_lego}.
|
||||
#' @param use_bricks Array of brick sizes to use in mosaic. Defaults to \code{c('4x2', '2x2', '3x1', '2x1', '1x1')}`.
|
||||
#' @param default_piece_type Piece type to use in absence of piece_type column.
|
||||
#' @return A list with element \code{Img_bricks} containing a data frame of the x- & y-coordinates, R, G, B channels, and brick ID. Other helper elements.
|
||||
|
||||
@@ -5,9 +5,8 @@
|
||||
#' @param img Image matrix to convert into mosaic. Usually from \code{\link[jpeg]{readJPEG}} or \code{\link[png]{readPNG}}.
|
||||
#' @param img_size Size of output image in pixel, where one pixel = one 'brick'. Use a single value (e.g. \code{48}) for a square image with 48 pixels on each side.
|
||||
#' Use an array of two values for a rectangular image \code{c(width, height)}.
|
||||
#' @param method The method to use for comparison. Either 'brickr_classic', 'euclidean', 'cie1976', 'cie94', 'cie2000', or 'cmc'.
|
||||
#' 'brickr_classic' is an explicit euclidean distance formula, but yield different results than 'euclidean' in {farver}.
|
||||
#' See \code{farver::compare_colour}.
|
||||
#' @param method The method to use for comparison. Options are 'euclidean', 'cie1976', 'cie94', 'cie2000', or 'cmc'.
|
||||
#' See \code{\link[farver]{compare_colour}}.
|
||||
#' @param color_table Defaults to \code{lego_colors}. Data frame of brick colors to map onto image. Must contain Name and R, G, B channels.
|
||||
#' See attached data \code{lego_colors} as examples.
|
||||
#' @param color_palette Brick color rarity to use. Defaults to all colors: 'universal' (most common), 'generic', and 'special' (least common). This is useful when trying to build the mosaic out of real bricks.
|
||||
@@ -21,20 +20,55 @@
|
||||
#' @family Mosaics
|
||||
#' @export
|
||||
#' @examples
|
||||
#' \donttest{
|
||||
#' # Create a random 24x24 'image'.
|
||||
#' # Otherwise, use a jpeg or png
|
||||
#' demo_image = array(scales::rescale(runif(24*24*3), c(0, 1)), dim=c(24, 24, 3))
|
||||
#'
|
||||
#' demo_image %>%
|
||||
#' image_to_mosaic(img_size = 24) %>%
|
||||
#' build_mosaic()
|
||||
#' # Import a jpeg or png
|
||||
#' demo_file <- system.file("extdata", "demo_img.jpg",
|
||||
#' package = "brickr", mustWork = TRUE)
|
||||
#' demo_image <- jpeg::readJPEG(demo_file)
|
||||
#'
|
||||
#' #Only use the most common "universal" LEGO colors
|
||||
#' #Create a 24x24 mosaic
|
||||
#' \donttest{
|
||||
#' demo_image %>%
|
||||
#' image_to_mosaic(img_size = 24, color_palette = "universal") %>%
|
||||
#' image_to_mosaic(img_size = 24) %>%
|
||||
#' build_mosaic()
|
||||
#' }
|
||||
#' }
|
||||
#'
|
||||
#' #Only use the two more common tiers of colors
|
||||
#' \donttest{
|
||||
#' demo_image %>%
|
||||
#' image_to_mosaic(img_size = 24,
|
||||
#' color_palette = c("universal", "generic")) %>%
|
||||
#' build_mosaic()
|
||||
#' }
|
||||
#'
|
||||
#' #Be more prescriptive with colors using 'color_table'.
|
||||
#' # Here, we prevent all blues from being used
|
||||
#' lego_colors_no_blue = lego_colors %>%
|
||||
#' dplyr::filter(!grepl("[Bb]lue|[Aa]zur", Color))
|
||||
#' \donttest{
|
||||
#' demo_image %>%
|
||||
#' image_to_mosaic(img_size = 24,
|
||||
#' color_table = lego_colors_no_blue) %>%
|
||||
#' build_mosaic()
|
||||
#' }
|
||||
#'
|
||||
#' #Color matching is done with the 'farver' package. There are different method.
|
||||
#' # Change the method to euclidean (RGB distance matching)
|
||||
#' \donttest{
|
||||
#' demo_image %>%
|
||||
#' image_to_mosaic(img_size = 24,
|
||||
#' method = "euclidean") %>%
|
||||
#' build_mosaic()
|
||||
#' }
|
||||
#'
|
||||
#' #Change the default size of bricks to use.
|
||||
#' # In this extreme example, use 4x6s for the background, 1x1 everywhere else
|
||||
#' \donttest{
|
||||
#' demo_image %>%
|
||||
#' image_to_mosaic(img_size = 24,
|
||||
#' use_bricks = c("4x6")) %>%
|
||||
#' build_mosaic()
|
||||
#' }
|
||||
#'
|
||||
#'
|
||||
image_to_mosaic <- function(img, img_size = 48, color_table = NULL,
|
||||
method = "cie94",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#' Scale an image raster array to a small number of pixels.
|
||||
#' Scale an image raster array to a small number of pixels
|
||||
#'
|
||||
#' Decrease the size of an image, in pixel. Process into a data frame. Internal function.
|
||||
#'
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#' Generate required bricks as a data frame.
|
||||
#' Generate required bricks as a data frame
|
||||
#'
|
||||
#' Create a dataframe of brick colors and sizes used in a brick mosaic or model.
|
||||
#'
|
||||
@@ -6,15 +6,23 @@
|
||||
#' @return Data frame of piece counts by LEGO color name and size.
|
||||
#' @family Resources
|
||||
#' @export
|
||||
#' @examples \donttest{
|
||||
#' # Create a random 24x24 'image'.
|
||||
#' # Otherwise, use a jpeg or png
|
||||
#' demo_image = array(scales::rescale(runif(24*24*3), c(0, 1)), dim=c(24, 24, 3))
|
||||
#'
|
||||
#' demo_image %>%
|
||||
#' image_to_mosaic(img_size = 24) %>%
|
||||
#' build_pieces_table()
|
||||
#'}
|
||||
#' @examples
|
||||
#' # Import a jpeg or png
|
||||
#' demo_file <- system.file("extdata", "demo_img.jpg",
|
||||
#' package = "brickr", mustWork = TRUE)
|
||||
#' demo_image <- jpeg::readJPEG(demo_file)
|
||||
#' #Create a mosaic oject
|
||||
#' \donttest{
|
||||
#' mosaic <- demo_image %>%
|
||||
#' image_to_mosaic(img_size = 24)
|
||||
#' }
|
||||
#'
|
||||
#' #Rather than drawing the mosaic, use build_pieces_table() to produce piece table
|
||||
#' \donttest{
|
||||
#' mosaic %>%
|
||||
#' build_pieces_table()
|
||||
#' }
|
||||
|
||||
|
||||
build_pieces_table <- function(brick_obj){
|
||||
pcs <- brick_obj$pieces
|
||||
@@ -25,7 +33,7 @@ build_pieces_table <- function(brick_obj){
|
||||
dplyr::rename(`LEGO Brick Color` = Lego_name)
|
||||
}
|
||||
|
||||
#' Display bricks required to build model or mosaic.
|
||||
#' Display bricks required to build model or mosaic
|
||||
#'
|
||||
#' Create a chart of brick colors and sizes used in a brick mosaic or model.
|
||||
#'
|
||||
@@ -33,16 +41,22 @@ build_pieces_table <- function(brick_obj){
|
||||
#' @return Plot object of required bricks by color and size.
|
||||
#' @family Resources
|
||||
#' @export
|
||||
#' @examples \donttest{
|
||||
#' # Create a random 24x24 'image'.
|
||||
#' # Otherwise, use a jpeg or png
|
||||
#' demo_image = array(scales::rescale(runif(24*24*3), c(0, 1)), dim=c(24, 24, 3))
|
||||
#'
|
||||
#' demo_image %>%
|
||||
#' image_to_mosaic(img_size = 24) %>%
|
||||
#' build_pieces()
|
||||
#'}
|
||||
#'
|
||||
#' @examples
|
||||
#' # Import a jpeg or png
|
||||
#' demo_file <- system.file("extdata", "demo_img.jpg",
|
||||
#' package = "brickr", mustWork = TRUE)
|
||||
#' demo_image <- jpeg::readJPEG(demo_file)
|
||||
#' #Create a mosaic oject
|
||||
#' \donttest{
|
||||
#' mosaic <- demo_image %>%
|
||||
#' image_to_mosaic(img_size = 24)
|
||||
#' }
|
||||
#'
|
||||
#' #Rather than drawing the mosaic, use build_pieces_table() to draw piece chart
|
||||
#' \donttest{
|
||||
#' mosaic %>%
|
||||
#' build_pieces()
|
||||
#' }
|
||||
|
||||
build_pieces <- function(brick_obj){
|
||||
in_list <- brick_obj
|
||||
|
||||
@@ -17,5 +17,8 @@ This is my first CRAN submission.
|
||||
|
||||
Re-submit with improvements to documentation.
|
||||
|
||||
Most examples that produce the mosaics or 3D models take more than 5 seconds to calculate.
|
||||
Those lines of script have been wrapped in donttest. There are a few cases where I got the examples to run quickly without donttest.
|
||||
|
||||
## Downstream dependencies
|
||||
No downstream dependencies
|
||||
@@ -65,27 +65,31 @@ brick \%>\%
|
||||
|
||||
#This is a lot of bricks
|
||||
bricks <- expand.grid(
|
||||
x = 1:8,
|
||||
y = 1:4,
|
||||
x = 1:4,
|
||||
y = 1:2,
|
||||
z = 1:3)
|
||||
|
||||
#Color them in sets of these 3 options
|
||||
bricks$color <- rep(rep(c("Bright yellow", "Bright red", "Tr. green"), each=4), 8)
|
||||
bricks$color <- rep(rep(c("Bright yellow", "Bright red", "Tr. green"), each=4), 2)
|
||||
|
||||
\donttest{
|
||||
bricks \%>\%
|
||||
bricks_from_coords() \%>\%
|
||||
build_bricks()
|
||||
|
||||
rgl::clear3d()
|
||||
}
|
||||
|
||||
#Use different brick shapes by added a 'piece_type' column
|
||||
bricks$piece_type <- "c1" #Make all the pieces cylinders
|
||||
|
||||
\donttest{
|
||||
bricks \%>\%
|
||||
bricks_from_coords() \%>\%
|
||||
build_bricks()
|
||||
|
||||
rgl::clear3d()
|
||||
}
|
||||
|
||||
}
|
||||
\seealso{
|
||||
|
||||
@@ -18,23 +18,39 @@ A list with elements \code{Img_lego} to pass to \code{\link{build_bricks}}.
|
||||
}
|
||||
\description{
|
||||
Stacks LEGO plates to create a 3D version of the 2D brick mosaics.
|
||||
}
|
||||
\details{
|
||||
Height of bricks determined by brightness of color.
|
||||
}
|
||||
\examples{
|
||||
\donttest{
|
||||
# Create a random 24x24 'image'.
|
||||
# Otherwise, use a jpeg or png
|
||||
demo_image = array(scales::rescale(runif(24*24*3), c(0, 1)), dim=c(24, 24, 3))
|
||||
|
||||
demo_image \%>\%
|
||||
image_to_mosaic(img_size = 24) \%>\%
|
||||
bricks_from_mosaic() \%>\%
|
||||
build_bricks()
|
||||
# Import a jpeg or png
|
||||
demo_file <- system.file("extdata", "demo_img.jpg",
|
||||
package = "brickr", mustWork = TRUE)
|
||||
demo_image <- jpeg::readJPEG(demo_file)
|
||||
|
||||
rgl::clear3d()
|
||||
}
|
||||
#Begin with a 24x24 mosaic object
|
||||
\donttest{
|
||||
mosaic <- demo_image \%>\%
|
||||
image_to_mosaic(24)
|
||||
}
|
||||
|
||||
#Pass the mosaic object to bricks_from_mosaic() to convert to 3D specifications
|
||||
\donttest{
|
||||
mosaic \%>\%
|
||||
bricks_from_mosaic() \%>\%
|
||||
build_bricks()
|
||||
|
||||
rgl::clear3d()
|
||||
}
|
||||
|
||||
#In this image, the background is a light color.
|
||||
# Change the 'highest_el' to make dark colors highest
|
||||
# Change mosaic height to change the number of layers
|
||||
\donttest{
|
||||
mosaic \%>\%
|
||||
bricks_from_mosaic(mosaic_height = 3, highest_el = "dark") \%>\%
|
||||
build_bricks()
|
||||
|
||||
rgl::clear3d()
|
||||
}
|
||||
}
|
||||
\seealso{
|
||||
Other 3D Models:
|
||||
|
||||
@@ -90,11 +90,14 @@ pieces <- data.frame(
|
||||
X1 = c("b", "b", "p", "p"), #b is brick (default), p is plate
|
||||
X2 = c("b", "b", "p", "p")
|
||||
)
|
||||
|
||||
\donttest{
|
||||
brick \%>\%
|
||||
bricks_from_table(piece_matrix=pieces) \%>\%
|
||||
build_bricks()
|
||||
|
||||
rgl::clear3d()
|
||||
}
|
||||
|
||||
#Provide a custom table of colors
|
||||
custom_colors <- data.frame(
|
||||
@@ -102,18 +105,22 @@ custom_colors <- data.frame(
|
||||
Color = c("Bright orange", "Dark green")
|
||||
)
|
||||
|
||||
\donttest{
|
||||
brick \%>\%
|
||||
bricks_from_table(color_guide = custom_colors) \%>\%
|
||||
build_bricks()
|
||||
|
||||
rgl::clear3d()
|
||||
}
|
||||
|
||||
#Limit the size of bricks used in the model with use_bricks
|
||||
\donttest{
|
||||
brick \%>\%
|
||||
bricks_from_table(use_bricks = "2x1") \%>\% #Only use 2x1 bricks.
|
||||
build_bricks()
|
||||
|
||||
rgl::clear3d()
|
||||
}
|
||||
}
|
||||
\seealso{
|
||||
Other 3D Models:
|
||||
|
||||
@@ -31,10 +31,9 @@ Set to 'TRUE' and rgl_lit='FALSE' for cartoon-looking bricks.}
|
||||
3D brick model rendered in the 'rgl' package.
|
||||
}
|
||||
\description{
|
||||
Render the output of any of the \code{bricks_from_*} functions as a 3D model.
|
||||
Render the output of any of the \code{bricks_from_*} functions as a 3D model. Opens an 'rgl' window.
|
||||
}
|
||||
\examples{
|
||||
\donttest{
|
||||
#This is a brick
|
||||
brick <- data.frame(
|
||||
Level="A",
|
||||
@@ -42,12 +41,23 @@ brick <- data.frame(
|
||||
X2 = rep(3,4)
|
||||
)
|
||||
|
||||
brick \%>\%
|
||||
bricks_from_table() \%>\%
|
||||
build_bricks()
|
||||
#Convert the dataframe to a list object that can be rendered
|
||||
brick_object <- brick \%>\%
|
||||
bricks_from_table()
|
||||
|
||||
#Render it
|
||||
brick_object \%>\%
|
||||
build_bricks()
|
||||
|
||||
rgl::clear3d()
|
||||
}
|
||||
|
||||
#Combine the option rgl_lit=FALSE & outline_bricks=TRUE
|
||||
# This makes the rendering look like a drawing
|
||||
brick_object \%>\%
|
||||
build_bricks(outline_bricks = TRUE, rgl_lit = FALSE,
|
||||
background_color = "#99e7ff")
|
||||
rgl::clear3d()
|
||||
|
||||
}
|
||||
\seealso{
|
||||
Other 3D Models:
|
||||
|
||||
@@ -15,16 +15,15 @@ build_colors(.names_only = FALSE, include_transparent = TRUE)
|
||||
An array or ggplot of brick colors & ID numbers.
|
||||
}
|
||||
\description{
|
||||
Generates a plot of available brick colors.
|
||||
Generates a plot of available brick colors. These names must be used exactly when creating custom name lists.
|
||||
There are 41 solid brick color names and 13 transparent colors. Transparent colors are not used in mosaics.
|
||||
}
|
||||
\details{
|
||||
Use .names_only = TRUE to get a list of color names.
|
||||
}
|
||||
\examples{
|
||||
#Generate plot of colors
|
||||
\donttest{
|
||||
build_colors()
|
||||
}
|
||||
build_colors(include_transparent = FALSE)
|
||||
|
||||
#Print list of colors
|
||||
build_colors(TRUE)
|
||||
|
||||
@@ -25,15 +25,28 @@ This makes it easier to follow each row when building an actual brick mosaic.
|
||||
The current model level is clearly displayed, while the previous level is shows as transparent.
|
||||
}
|
||||
\examples{
|
||||
\donttest{
|
||||
# Create a random 24x24 'image'.
|
||||
# Otherwise, use a jpeg or png
|
||||
demo_image = array(scales::rescale(runif(24*24*3), c(0, 1)), dim=c(24, 24, 3))
|
||||
# Import a jpeg or png
|
||||
demo_file <- system.file("extdata", "demo_img.jpg",
|
||||
package = "brickr", mustWork = TRUE)
|
||||
demo_image <- jpeg::readJPEG(demo_file)
|
||||
|
||||
#Create a mosaic oject
|
||||
\donttest{
|
||||
mosaic <- demo_image \%>\%
|
||||
image_to_mosaic(img_size = 24)
|
||||
}
|
||||
|
||||
#Rather than drawing the mosaic, use build_instructions() to draw instructions
|
||||
\donttest{
|
||||
mosaic \%>\%
|
||||
build_instructions()
|
||||
}
|
||||
|
||||
demo_image \%>\%
|
||||
image_to_mosaic(img_size = 24) \%>\%
|
||||
build_instructions()
|
||||
}
|
||||
#Change the number of steps for more detail
|
||||
\donttest{
|
||||
mosaic \%>\%
|
||||
build_instructions(num_steps = 9)
|
||||
}
|
||||
|
||||
}
|
||||
\seealso{
|
||||
|
||||
@@ -20,11 +20,23 @@ Render a plot image of the 2D brick mosaic with optional title.
|
||||
\examples{
|
||||
|
||||
# Import a jpeg or png
|
||||
demo_image = system.file("extdata", "demo_img.jpg", package = "brickr", mustWork = TRUE)
|
||||
|
||||
jpeg::readJPEG(demo_image) \%>\%
|
||||
image_to_mosaic() \%>\%
|
||||
demo_file <- system.file("extdata", "demo_img.jpg",
|
||||
package = "brickr", mustWork = TRUE)
|
||||
demo_image <- jpeg::readJPEG(demo_file)
|
||||
|
||||
#Build a very small 12x12 mosaic.
|
||||
\donttest{
|
||||
demo_image \%>\%
|
||||
image_to_mosaic(12) \%>\%
|
||||
build_mosaic()
|
||||
}
|
||||
|
||||
#Build a mosaic in the default size of 48x48 studs with title
|
||||
\donttest{
|
||||
demo_image \%>\%
|
||||
image_to_mosaic() \%>\%
|
||||
build_mosaic("Demo mosaic")
|
||||
}
|
||||
}
|
||||
\seealso{
|
||||
Other Mosaics:
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
% Please edit documentation in R/piece-count.R
|
||||
\name{build_pieces}
|
||||
\alias{build_pieces}
|
||||
\title{Display bricks required to build model or mosaic.}
|
||||
\title{Display bricks required to build model or mosaic}
|
||||
\usage{
|
||||
build_pieces(brick_obj)
|
||||
}
|
||||
@@ -16,16 +16,21 @@ Plot object of required bricks by color and size.
|
||||
Create a chart of brick colors and sizes used in a brick mosaic or model.
|
||||
}
|
||||
\examples{
|
||||
\donttest{
|
||||
# Create a random 24x24 'image'.
|
||||
# Otherwise, use a jpeg or png
|
||||
demo_image = array(scales::rescale(runif(24*24*3), c(0, 1)), dim=c(24, 24, 3))
|
||||
|
||||
demo_image \%>\%
|
||||
image_to_mosaic(img_size = 24) \%>\%
|
||||
build_pieces()
|
||||
}
|
||||
|
||||
# Import a jpeg or png
|
||||
demo_file <- system.file("extdata", "demo_img.jpg",
|
||||
package = "brickr", mustWork = TRUE)
|
||||
demo_image <- jpeg::readJPEG(demo_file)
|
||||
#Create a mosaic oject
|
||||
\donttest{
|
||||
mosaic <- demo_image \%>\%
|
||||
image_to_mosaic(img_size = 24)
|
||||
}
|
||||
|
||||
#Rather than drawing the mosaic, use build_pieces_table() to draw piece chart
|
||||
\donttest{
|
||||
mosaic \%>\%
|
||||
build_pieces()
|
||||
}
|
||||
}
|
||||
\seealso{
|
||||
Other Resources:
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
% Please edit documentation in R/piece-count.R
|
||||
\name{build_pieces_table}
|
||||
\alias{build_pieces_table}
|
||||
\title{Generate required bricks as a data frame.}
|
||||
\title{Generate required bricks as a data frame}
|
||||
\usage{
|
||||
build_pieces_table(brick_obj)
|
||||
}
|
||||
@@ -16,15 +16,21 @@ Data frame of piece counts by LEGO color name and size.
|
||||
Create a dataframe of brick colors and sizes used in a brick mosaic or model.
|
||||
}
|
||||
\examples{
|
||||
\donttest{
|
||||
# Create a random 24x24 'image'.
|
||||
# Otherwise, use a jpeg or png
|
||||
demo_image = array(scales::rescale(runif(24*24*3), c(0, 1)), dim=c(24, 24, 3))
|
||||
|
||||
demo_image \%>\%
|
||||
image_to_mosaic(img_size = 24) \%>\%
|
||||
build_pieces_table()
|
||||
}
|
||||
# Import a jpeg or png
|
||||
demo_file <- system.file("extdata", "demo_img.jpg",
|
||||
package = "brickr", mustWork = TRUE)
|
||||
demo_image <- jpeg::readJPEG(demo_file)
|
||||
#Create a mosaic oject
|
||||
\donttest{
|
||||
mosaic <- demo_image \%>\%
|
||||
image_to_mosaic(img_size = 24)
|
||||
}
|
||||
|
||||
#Rather than drawing the mosaic, use build_pieces_table() to produce piece table
|
||||
\donttest{
|
||||
mosaic \%>\%
|
||||
build_pieces_table()
|
||||
}
|
||||
}
|
||||
\seealso{
|
||||
Other Resources:
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
% Please edit documentation in R/collect-bricks.R
|
||||
\name{collect_bricks}
|
||||
\alias{collect_bricks}
|
||||
\title{Consolidate 1x1 bricks into larger ones of the same color. Internal function.}
|
||||
\title{Consolidate 1x1 bricks into larger ones of the same color}
|
||||
\usage{
|
||||
collect_bricks(image_list, use_bricks = NULL, default_piece_type = "b")
|
||||
}
|
||||
\arguments{
|
||||
\item{image_list}{List output from legoize(). Contains an element \code{Img_lego}.}
|
||||
\item{image_list}{List output containing an element \code{Img_lego}.}
|
||||
|
||||
\item{use_bricks}{Array of brick sizes to use in mosaic. Defaults to \code{c('4x2', '2x2', '3x1', '2x1', '1x1')}`.}
|
||||
|
||||
@@ -17,6 +17,7 @@ collect_bricks(image_list, use_bricks = NULL, default_piece_type = "b")
|
||||
A list with element \code{Img_bricks} containing a data frame of the x- & y-coordinates, R, G, B channels, and brick ID. Other helper elements.
|
||||
}
|
||||
\description{
|
||||
Consolidate 1x1 bricks into larger ones of the same color. Internal function.
|
||||
Internal function for collecting single bricks into large ones. Used in both mosaics and 3D models.
|
||||
Automatically generate missing piece_type or mid_level.
|
||||
}
|
||||
\keyword{internal}
|
||||
|
||||
@@ -26,9 +26,8 @@ Use an array of two values for a rectangular image \code{c(width, height)}.}
|
||||
\item{color_table}{Defaults to \code{lego_colors}. Data frame of brick colors to map onto image. Must contain Name and R, G, B channels.
|
||||
See attached data \code{lego_colors} as examples.}
|
||||
|
||||
\item{method}{The method to use for comparison. Either 'brickr_classic', 'euclidean', 'cie1976', 'cie94', 'cie2000', or 'cmc'.
|
||||
'brickr_classic' is an explicit euclidean distance formula, but yield different results than 'euclidean' in {farver}.
|
||||
See \code{farver::compare_colour}.}
|
||||
\item{method}{The method to use for comparison. Options are 'euclidean', 'cie1976', 'cie94', 'cie2000', or 'cmc'.
|
||||
See \code{\link[farver]{compare_colour}}.}
|
||||
|
||||
\item{color_palette}{Brick color rarity to use. Defaults to all colors: 'universal' (most common), 'generic', and 'special' (least common). This is useful when trying to build the mosaic out of real bricks.
|
||||
Use "bw" for only grayscale bricks. Ignored if a \code{color_table} is supplied.}
|
||||
@@ -50,20 +49,55 @@ A list with element \code{Img_lego} containing a data frame of the x- & y-coordi
|
||||
Generate brick mosaics from an image or matrix with customization options.
|
||||
}
|
||||
\examples{
|
||||
\donttest{
|
||||
# Create a random 24x24 'image'.
|
||||
# Otherwise, use a jpeg or png
|
||||
demo_image = array(scales::rescale(runif(24*24*3), c(0, 1)), dim=c(24, 24, 3))
|
||||
|
||||
demo_image \%>\%
|
||||
image_to_mosaic(img_size = 24) \%>\%
|
||||
build_mosaic()
|
||||
# Import a jpeg or png
|
||||
demo_file <- system.file("extdata", "demo_img.jpg",
|
||||
package = "brickr", mustWork = TRUE)
|
||||
demo_image <- jpeg::readJPEG(demo_file)
|
||||
|
||||
#Only use the most common "universal" LEGO colors
|
||||
#Create a 24x24 mosaic
|
||||
\donttest{
|
||||
demo_image \%>\%
|
||||
image_to_mosaic(img_size = 24, color_palette = "universal") \%>\%
|
||||
image_to_mosaic(img_size = 24) \%>\%
|
||||
build_mosaic()
|
||||
}
|
||||
}
|
||||
|
||||
#Only use the two more common tiers of colors
|
||||
\donttest{
|
||||
demo_image \%>\%
|
||||
image_to_mosaic(img_size = 24,
|
||||
color_palette = c("universal", "generic")) \%>\%
|
||||
build_mosaic()
|
||||
}
|
||||
|
||||
#Be more prescriptive with colors using 'color_table'.
|
||||
# Here, we prevent all blues from being used
|
||||
lego_colors_no_blue = lego_colors \%>\%
|
||||
dplyr::filter(!grepl("[Bb]lue|[Aa]zur", Color))
|
||||
\donttest{
|
||||
demo_image \%>\%
|
||||
image_to_mosaic(img_size = 24,
|
||||
color_table = lego_colors_no_blue) \%>\%
|
||||
build_mosaic()
|
||||
}
|
||||
|
||||
#Color matching is done with the 'farver' package. There are different method.
|
||||
# Change the method to euclidean (RGB distance matching)
|
||||
\donttest{
|
||||
demo_image \%>\%
|
||||
image_to_mosaic(img_size = 24,
|
||||
method = "euclidean") \%>\%
|
||||
build_mosaic()
|
||||
}
|
||||
|
||||
#Change the default size of bricks to use.
|
||||
# In this extreme example, use 4x6s for the background, 1x1 everywhere else
|
||||
\donttest{
|
||||
demo_image \%>\%
|
||||
image_to_mosaic(img_size = 24,
|
||||
use_bricks = c("4x6")) \%>\%
|
||||
build_mosaic()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
\seealso{
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
% Please edit documentation in R/image-to-prep-mosaic.R
|
||||
\name{image_to_scaled}
|
||||
\alias{image_to_scaled}
|
||||
\title{Scale an image raster array to a small number of pixels.}
|
||||
\title{Scale an image raster array to a small number of pixels}
|
||||
\arguments{
|
||||
\item{image}{A raster array from an image.}
|
||||
|
||||
|
||||
@@ -105,10 +105,10 @@ png::readPNG(demo_img) %>%
|
||||
|
||||
brickr uses the [`farver`](https://CRAN.R-project.org/package=farver) package to match image colors to the subset of LEGO colors. Technical details of the different algorithms can be found on [Wikipedia](https://en.wikipedia.org/wiki/Color_difference).
|
||||
|
||||
The default algorithm is 'cie94', though the other farver options are available using the `method` input. The farver 'euclidean' is not very accurate, so 'brickr_classic' returns a manually calculated version for Euclidean RGB distance matching.
|
||||
The default algorithm is 'cie94', though the other farver options are available using the `method` input.
|
||||
|
||||
```{r c_methods, fig.height=5, fig.width=5}
|
||||
c("cie94", "cie2000", "euclidean", "brickr_classic") %>%
|
||||
c("cie94", "cie2000", "euclidean", "cmc") %>%
|
||||
purrr::map(~png::readPNG(demo_img) %>%
|
||||
image_to_mosaic(24, method =.x) %>%
|
||||
build_mosaic(title = .x )) -> mosaics_by_method
|
||||
|
||||
Reference in New Issue
Block a user