average: Average several colors

View source: R/compute_average.R

averageR Documentation

Average several colors

Description

Average several colors

Usage

average(x, model = "lrgb", na.rm = FALSE)

Arguments

x

vector of colors specified as hex strings or named R colors.

model

string defining the color model to compute the mix in; valid models are hcl, lch, hsi, hsl, hsv, lab, rgb, lrgb.

na.rm

a logical value indicating whether NA values should be stripped before the computation proceeds.

Value

A vector of colors specified as hex codes

See Also

Other color manipulation functions: blend(), channel(), darken(), luminance(), mix(), saturate()

Examples

average(c("red", "blue"))
average(c("red", "blue", "green"))

# show the input colors, then white, then the average
show_ave <- function(x, ...) {show_col(c(x, "white", average(x, ...)))}

show_ave(c("#FEF213", "#146EFD"))
show_ave(hue_colors(5))
show_ave(brewer_colors(5, name="Set3"))
show_ave(cubehelix_colors(5))
# so averaging produces brown, most of the time, but not always:
show_ave(brewer_colors(5, name="Greens"))

# beware that numerical color averaging is not the same as blending
# pigments, in particular in non-rgb spaces
show_ave(c("#FEF213", "#A0BD71", "#146EFD"))
show_ave(c("#FEF213", "#A0BD71", "#146EFD"), model="hcl")
show_ave(c("#FEF213", "#A0BD71", "#146EFD"), model="hsv")
show_ave(c("#FEF213", "#A0BD71", "#146EFD"), model="lab")

jiho/chroma documentation built on Nov. 26, 2022, 2:39 a.m.