Created
October 3, 2023 05:51
-
-
Save chelseaparlett/64d0154c2b3bdd279e2805326cc21f89 to your computer and use it in GitHub Desktop.
Lego 5x5x3 Imagewith 3x3x3 kernel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(brickr) | |
make_bricks <- function(brick_width = 5, | |
brick_length = 5, | |
n_layers = 3, | |
colors = c("Bright red", | |
"Bright green", | |
"Bright blue"), | |
render = FALSE){ | |
x <- rep(sort(rep(1:brick_width, brick_length)), n_layers) | |
y <- rep(1:brick_length, n_layers*brick_width) | |
z <- sort(rep(1:n_layers,brick_width * brick_length)) | |
bricks <- data.frame(x = x, y = y, z = z) | |
#Color them in sets of these 3 options | |
bricks$color <- sort(rep(colors, brick_length * brick_width)) | |
if (render){ | |
bricks %>% bricks_from_coords(use_bricks = c("1x1")) %>% build_bricks() | |
} | |
return(bricks) | |
} | |
move_kernel <- function(image,kernel,x = 0, y = 0){ | |
kernel$z <- kernel$z + 3 | |
kernel$x <- kernel$x + x | |
kernel$y <- kernel$y + y | |
df <- rbind(image,kernel) | |
df %>% bricks_from_coords(use_bricks = c("1x1")) %>% build_bricks() | |
} | |
image <- make_bricks() | |
kernel <- make_bricks(3,3,3, colors = rep("Medium stone grey",3)) | |
move_kernel(image, kernel) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment