contrast: Quantify contrast betwen colors

View source: R/compute_contrast.R

contrastR Documentation

Quantify contrast betwen colors

Description

Compute the WCAG contrast ratio between two colors.

Usage

contrast(x, y)

Arguments

x, y

colors specified as hex strings or named R colors.

Value

A number giving the contrast ratio between x and y (or a vector thereof). A value of 1 means no contrast at all. A minimum contrast of 4.5 is recommended to ensure that text is still readable against a background color.

References

https://www.w3.org/TR/WCAG20-TECHS/G18.html

Examples

contrast("pink", "hotpink")
contrast("pink", "blue")

# The computation can be vectorised (if the arguments are compatible)
contrast("pink", rainbow(10))
contrast(c("red","pink"), c("red","blue"))

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