R/makeTrans.R

Defines functions makeTrans

Documented in makeTrans

#' makeTrans
#'
#' Some function from stack exchange that makes a colour transparent according to a given alpha.
#' @param alpha The alpha required.
#' @name makeTrans
#' @export

makeTrans <- function(..., alpha=0.5) {
  if(alpha<0 | alpha>1) {
    stop("alpha must be between 0 and 1")
  }
 
  alpha <- floor(255*alpha) 
  newColor <- col2rgb(col=unlist(list(...)), alpha=FALSE)

  .makeTrans <- function(col, alpha) {
    rgb(red=col[1], green=col[2], blue=col[3], alpha=alpha, maxColorValue=255)
  }

  newColor <- apply(newColor, 2, .makeTrans, alpha=alpha)
  return(newColor)
}
hferg/bayestraitr documentation built on May 28, 2019, 8:55 p.m.