Average colors by list

avg_colors_by_list(
  x,
  useWeightedHue = TRUE,
  Cmethod = c("mean", "max", "min"),
  Lmethod = c("mean", "max", "min"),
  c_min = 4,
  grey_hue = 359,
  ...
)

Arguments

x

list of character vectors.

useWeightedHue

logical indicating whether to weight the hue wheel using colorjam::h2hw() and colorjam::hw2h() which effectively converts the RGB angles to RYB (red-yellow-blue), and therefore makes additive color blending more sensible. Specifically, "yellow and blue makes green".

...

additional arguments are ignored.

Value

vector of R colors.

Details

This is a simple wrapper function intended to provide a rapid average color, when supplied a list of color vectors in hex or R color name format.

This function simply converts each color to HCL, determines the color hue angle (from 0 to 360) then calculates the average angular color hue using avg_angles(), then applies that to the maximum C and L values to determine the new color. It is deliberately intended to ignore muddiness when averaging multiple colors.

Colors are only modified for elements with 2 or more entries.

This method also only operates on the unique set of colors, so it should be substantially more efficient on large lists that contain only a few unique subsets of colors.

Examples

x <- list(input1=c(red="red", blue="blue"),
   input2=c(blue="blue", gold="gold"),
   input3=c(red="red", yellow="yellow"));
x_avg <- avg_colors_by_list(x, useWeightedHue=TRUE);
jamba::showColors(list(
   input1=c(x[[1]], x_avg[1]),
   input2=c(x[[2]], x_avg[2]),
   input2=c(x[[3]], x_avg[3])),
   main="With weighted hue")


x_avg <- avg_colors_by_list(x, useWeightedHue=FALSE);
jamba::showColors(list(
   input1=c(x[[1]], x_avg[1]),
   input2=c(x[[2]], x_avg[2]),
   input2=c(x[[3]], x_avg[3])),
   main="Without weighted hue")