#' Get color's brightness
#'
#' Get the brightness of a color vector.
#'
#' @param x a any type color string or a javascript color object specifying.
#' @param na.rm a logical value indicating whether NA values should be stripped before the computation proceeds.
#'
#' @return Returns the brightness of the color, values in the range of 0 to 255.
#' @export
#' @examples
#' get_brightness("#F00")
#' get_brightness("{ r: 1, g: 0, b: 0 }")
#' get_brightness("{ h: 0.5, s: 0.5, v: 0.5 }")
get_brightness <- function(x, na.rm = FALSE) {
if(na.rm) x <- x[! is.na(x)]
cmd <- ifelse(is_js_object(x),
paste0("tinycolor(", x, ").getBrightness()"),
paste0("tinycolor(\"", x, "\").getBrightness()"))
out <- as.numeric(v8_eval(cmd))
return(out)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.