| library(tidyverse) | |||||
| read_colors <- function(file) { | |||||
| text <- readLines(file, warn = FALSE) %>% | |||||
| str_subset("#[0-9a-fA-F]{6}") # must be len-6 hex | |||||
| str_match_all(text, "\\$(.+)\\s*:\\s*(#[0-9a-fA-F]{6});") %>% | |||||
| discard(~ length(.) < 1) %>% | |||||
| map_dfr(~ tibble(name = .[, 2], color = .[, 3])) %>% | |||||
| distinct(name, color) %>% | |||||
| mutate(name = factor(name, unique(name))) | |||||
| } | |||||
| show_colors <- function(colors) { | |||||
| ggplot(colors) + | |||||
| aes(1, 1, fill = color) + | |||||
| geom_tile() + | |||||
| facet_wrap(~ name + color) + | |||||
| scale_fill_identity() + | |||||
| theme_void() | |||||
| } |