diff --git a/R/colors-and-themes.R b/R/colors-and-themes.R index 5a3c0df..bdad7fc 100644 --- a/R/colors-and-themes.R +++ b/R/colors-and-themes.R @@ -2,7 +2,8 @@ #' #' Generates a plot of available brick colors. Use .names_only = TRUE to get a list of color names. #' -#' @param .names_only Return an array of the 41 brick color names. Does not plot. +#' @param .names_only Return an array of the 41 solid brick color names and 13 transparent colors. Does not plot. +#' @param include_transparent Include transparent colors in the plot output. #' @return A table and ggplot of brick colors & ID numbers. #' @examples #' #Generate plot of colors @@ -13,25 +14,44 @@ #' @family Resources #' @export -build_colors <- function(.names_only = FALSE){ +build_colors <- function(.names_only = FALSE, include_transparent = TRUE){ if(.names_only){ return(lego_colors$Color) } message("Use View(lego_colors) to see these in a table format.") - tidyr::crossing(x=1:2, y=1:2, color = lego_colors$Color) %>% - dplyr::left_join(lego_colors %>% dplyr::select(color = Color, color_hex = hex), by = "color") %>% - dplyr::mutate(color = factor(gsub(" ", "\n", color), - levels = gsub(" ", "\n", lego_colors$Color))) %>% + if(include_transparent){ + message("Transparent colors are only used for 3D models, not color matching in mosaics or ggplot.") + + use_colors <- lego_colors$Color + use_columns <- 12 + } else{ + use_colors <- lego_colors %>% + dplyr::filter(!Trans_lego) %>% + pull(Color) + + use_columns <- 9 + } + + tidyr::crossing(x=1:2, y=1:2, color = use_colors) %>% + dplyr::left_join(lego_colors %>% + dplyr::select(color = Color, color_hex = hex, Trans_lego), by = "color") %>% + dplyr::mutate(color = factor(gsub('(.{1,8})(\\s|$)', '\\1\n', color), + levels =gsub('(.{1,8})(\\s|$)', '\\1\n', use_colors)), + alpha = ifelse(Trans_lego, 0.5, 1)) %>% ggplot2::ggplot(aes(x=x, y=y, group=color)) + ggplot2::labs(title = "Brick colors available in {brickr}") + - geom_brick_rect(aes(fill = color_hex), label_scale = 0.1, + geom_brick_rect(aes(fill = color_hex, alpha = alpha), label_scale = 0.1, #Including the use_bricks inputs greatly increases the speed of this. use_bricks = c("2x2")) + ggplot2::coord_fixed(x=c(0.5, 2.5), y=c(0.5, 2.5)) + ggplot2::scale_fill_identity() + - ggplot2::facet_wrap(~color, ncol = 9) + - ggplot2::theme_void() + ggplot2::scale_alpha_identity()+ + ggplot2::facet_wrap(~color, ncol = use_columns) + + ggplot2::theme_void() + + ggplot2::theme( + legend.position = "none" + ) } diff --git a/R/image-to-prep-mosaic.R b/R/image-to-prep-mosaic.R index dcbaad4..a8c42d0 100644 --- a/R/image-to-prep-mosaic.R +++ b/R/image-to-prep-mosaic.R @@ -117,7 +117,9 @@ scaled_to_colors <- function(image_list, method = "cie94", #Brick colors to use ---- if(is.null(color_table)) { - brick_table <- lego_colors + brick_table <- lego_colors %>% + #No transparent colors in mosaics + dplyr::filter(!Trans_lego) } else{ brick_table <- color_table } @@ -277,8 +279,8 @@ convert_color_to_brick_dithering <- function(img_object, color_table, brick_tabl mosaic_base[mosaic_base$B > 1, "B"] <- 1 mosaic_base[mosaic_base$R < 0, "R"] <- 0 - mosaic_base[mosaic_base$G < 0, "R"] <- 0 - mosaic_base[mosaic_base$B < 0, "R"] <- 0 + mosaic_base[mosaic_base$G < 0, "G"] <- 0 + mosaic_base[mosaic_base$B < 0, "B"] <- 0 } } diff --git a/admin_color_tools/Colors_Master.xlsx b/admin_color_tools/Colors_Master.xlsx index 04a1364..531f138 100644 Binary files a/admin_color_tools/Colors_Master.xlsx and b/admin_color_tools/Colors_Master.xlsx differ diff --git a/admin_color_tools/color_rendering.R b/admin_color_tools/color_rendering.R index fe9d4d2..5da4e22 100644 --- a/admin_color_tools/color_rendering.R +++ b/admin_color_tools/color_rendering.R @@ -12,12 +12,13 @@ names(color_df) lego_colors <- color_df %>% select(-Sample) %>% rename_at(vars("R", "G", "B"), list(~paste0(., "_lego"))) %>% - filter(c_Palette2016, !c_Metallic, !c_Transparent, !c_Glow) %>% + rename(Trans_lego = c_Transparent) %>% + filter(c_Palette2016, !c_Metallic, !c_Glow) %>% select(-starts_with("c_")) %>% mutate(Palette = factor(Palette, levels = c("Universal", "Generic", "Special")), hex = rgb2hex(R_lego, G_lego, B_lego)) %>% mutate_at(vars(R_lego, G_lego, B_lego), list(~./255)) %>% - arrange(Palette, LEGONo) %>% + arrange(Trans_lego, Palette, LEGONo) %>% mutate(brickrID = row_number()) %>% select(brickrID, Color, LEGONo, Palette, everything()) %>% #Calculate brightness of color diff --git a/data/lego_colors.rda b/data/lego_colors.rda index d805a70..737fa54 100644 Binary files a/data/lego_colors.rda and b/data/lego_colors.rda differ