mix: Mix two colors

View source: R/compute_mix.R

mixR Documentation

Mix two colors

Description

Mix two colors

Usage

mix(x, y, ratio = 0.5, model = "lrgb")

Arguments

x, y

colors specified as hex strings or named R colors.

ratio

amount of y mixed in x; ratio = 0 means pure x, ratio = 1 means pure y.

model

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

Details

All arguments can be vectors, as long as they are of compatible length (shorter arguments will be repeated to the length of longer arguments)

Value

A vector of colors specified as hex codes

See Also

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

Examples

mix("red", "blue")
mix("red", "blue", 0.25)
# Arguments can be vectors and all mixes are returned
mix("red", "blue", c(0.25, 0.5, 0.75))

show_mix <- function(x, y, ...) {show_col(c(x, y, "white", mix(x, y, ...)))}
show_mix("#FEF213", "#146EFD")
show_mix("#FEF213", "#FA000C")
show_mix("#146EFD", "#FA000C")
show_mix("#146EFD", "#FA000C", ratio=c(0.25, 0.5, 0.75))
# note that results in some color models can be surprising
show_mix("#FEF213", "#146EFD",
         model=c("hcl", "lch", "hsi", "hsl", "hsv", "lab", "rgb", "lrgb"))

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