color_dissimilarity

Measure the similarity of colors in a palette, and choose dissimilar colors from them.
git clone https://git.eamoncaddigan.net/color_dissimilarity.git
Log | Files | Refs | README | LICENSE

color_utils.R (488B)


      1 #' Convert a colorspace RGB object into a vector of hex codes.
      2 #'
      3 #' I thought the function `colorspace::hex()` would do this but it doesn't seem
      4 #' to work. Maybe I'm doing something wrong?
      5 #'
      6 #' @param colors_rgb A colorspace RGB object
      7 #'
      8 #' @return A vector of hex codes.
      9 RGB2hex <- function(colors_rgb) {
     10   grDevices::rgb(pmin(colors_rgb@coords[, 'R'] / 255, 1),
     11                  pmin(colors_rgb@coords[, 'G'] / 255, 1),
     12                  pmin(colors_rgb@coords[, 'B'] / 255, 1))
     13 }
     14 
     15