# Read in base16 hex colors:
base16 <- read.csv("data/colors.csv", stringsAsFactors = FALSE)
# Colors to use from base16:
colorout <- list(normal = "base05",
negnum = "base08",
zero = "base09",
number = "base0A",
date = "base0C",
string = "base0B",
const = "base0E",
false = "base08",
true = "base0A",
infinite = "base0F",
stderror = "base04",
warn = "base0D",
error = "base08")
# Create a dataset which has for each scheme, each color type (normal, number
# etc.)
df <- data.frame(scheme = rep(unique(base16$scheme), each = length(colorout)))
df$type <- rep(names(colorout), length(unique(df$scheme)))
colorout <- data.frame(type = names (colorout), base = unlist(colorout))
df <- merge(df, colorout, by = "type")
df <- merge(df, base16, by = c("scheme", "base"))
# Colors to match to (from source of colorout::show256Colors):
c256 <- read.table("data/256Colors.dat")$V1
# Convert these to RGB:
rgb256 <- data.frame(t(do.call(cbind, lapply(c256, col2rgb))))
# Find the color that matches as close as possible:
df$colorout.number <- apply(col2rgb(df$color), 2, FUN = function(x) {
dist <- (rgb256$red - x[1])^2 +
(rgb256$green - x[2])^2 +
(rgb256$blue - x[3])^2
return(which.min(dist))})
base16 <- df
save(base16, file = "data/base16.rda")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.