R/closestColHex.R

Defines functions closestColHex

closestColHex <- function(target, n = 3, superset = grDevices::colours(distinct = TRUE)) {
  target <- as.numeric(grDevices::col2rgb(target))

  dist_mat <- grDevices::col2rgb(superset) - target

  dist <- apply(dist_mat, 2, function(x) sum(abs(x)))

  closest <- order(dist)[1:n]

  superset[closest]
}

Try the ggedit package in your browser

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

ggedit documentation built on July 8, 2020, 5:34 p.m.