R/pal_mix.R

Defines functions pal_mix

pal_mix <- function(x) {
  x_mat <- farver::decode_colour(x, to = "xyz")
  sum_mix <- t(as.matrix(colSums(x_mat)))
  hex <- farver::encode_colour(sum_mix, from = "xyz")
  # This probably isn't realistic, but ensures that red + yellow gives orange,
  # because sum mix gives yellow
  if (hex %in% str_to_hex(x)) {
    mean_mix <- t(as.matrix(colMeans(x_mat)))
    hex <- farver::encode_colour(mean_mix, from = "xyz")
  }
  as_colour(hex)
}

Try the palettes package in your browser

Any scripts or data that you put into this service are public.

palettes documentation built on Sept. 11, 2024, 5:57 p.m.