blend: Blend two colors

View source: R/compute_blend.R

blendR Documentation

Blend two colors

Description

Blend two colors using RGB channel-wise blend functions.

Usage

blend(x, y, mode = "multiply")

Arguments

x, y

colors specified as hex strings or named R colors.

mode

blending mode; valid modes are multiply, darken, lighten, screen, overlay, burn, and dodge.

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(), channel(), darken(), luminance(), mix(), saturate()

Examples

blend("#4CBBFC", "#EEEE22")
# Arguments can be vectors and all blends are returned
mix("red", c("blue", "darkblue", "lightblue"))

#' Show the effects of the various blend modes
all_blends <- function(x, y) {
  c(x, y,
    "white",
    blend(x, y, mode=c("multiply", "darken", "lighten",
                       "screen", "overlay", "burn", "dodge"))
   )
}
show_col(
  all_blends("#FEF213", "#146EFD"),
  all_blends("#146EFD", "#FEF213"),
  all_blends("#FEF213", "#FA000C"),
  all_blends("#FA000C", "#FEF213"),
  all_blends("#146EFD", "#FA000C"),
  all_blends("#FA000C", "#146EFD")
)
# NB: for some blending modes, the order of the input colors is important

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