Create a 3D brick object from a data frame. Left-most column is level/height/z dimension, with rows as Y axis and columns as X axis.

bricks_from_table(
  matrix_table,
  color_guide = brickr::lego_colors,
  piece_matrix = NULL,
  use_bricks = NULL,
  .re_level = TRUE,
  increment_level = 0,
  min_level = 1,
  max_level = Inf,
  increment_x = 0,
  max_x = Inf,
  increment_y = 0,
  max_y = Inf,
  exclude_color = NULL,
  exclude_level = NULL
)

Arguments

matrix_table

A data frame of a 3D brick model design. Left-most column is level/height/z dimension, with rows as Y axis and columns as X axis. See example. Use tribble for ease.

color_guide

A data frame linking numeric .value in matrix_table to official LEGO color names. Defaults to data frame 'lego_colors'.

piece_matrix

A data frame in same shape as matrix_table with piece shape IDs.

use_bricks

Array of brick sizes to use in mosaic. Defaults to c('4x2', '2x2', '3x1', '2x1', '1x1')`. '1x1' will always be considered.

.re_level

Logical to reassign the Level/z dimension to layers in alphanumeric order. Set to FALSE to explicitly provide levels.

increment_level

Default '0'. Use in animations. Shift Level/z dimension by an integer.

min_level

Default '1'. Use in animations. Any Level/z values below this value will be cut off.

max_level

Default 'Inf'. Use in animations. Any Level/z values above this value will be cut off.

increment_x

Default '0'. Use in animations. Shift x dimension by an integer.

max_x

Default 'Inf'. Use in animations. Any x values above this value will be cut off.

increment_y

Default '0'. Use in animations. Shift y dimension by an integer.

max_y

Default 'Inf'. Use in animations. Any y values above this value will be cut off.

exclude_color

Numeric array of color ID numbers to exclude.

exclude_level

Numeric array of Level/z dimensions to exclude.

Value

A list with elements Img_lego to pass to build_bricks.

See also

Examples

#This is a 4x2 brick. One level high, 2 x-values (columns), 4 y-values (rows). brick <- data.frame( Level="A", X1 = rep(3,4), #The number 3 is the brickrID for 'bright red' X2 = rep(3,4) ) brick %>% bricks_from_table() %>% build_bricks() rgl::clear3d() #Build on top of each other by changing the Level value. #This example builds a blue 2x2 brick on top of a red 2x2 brick <- data.frame( Level=c("A", "A", "B", "B"), X1 = c(3, 3, 4, 4), #3 is red, 4 is blue X2 = c(3, 3, 4, 4) ) brick %>% bricks_from_table() %>% build_bricks() rgl::clear3d() #Provide an additional piece_matrix argument to change the default brick shape. pieces <- data.frame( Level=c("A", "A", "B", "B"), 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( .value = c(3, 4), 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() # }