R/addTrans.R

Defines functions addTrans

Documented in addTrans

#' Apply transparency to a color
#' 
#' Add transparancy to a color. 
#' 
#' @param color One of the colors in the pallete.
#' @param trans Degree of transparancy. Define transparancy with an integer between 0 and 255. 0 being fully transparant and 255 being fully visable.
#' @export

addTrans <- function(color,trans)
{
  if (length(color)!=length(trans)&!any(c(length(color),length(trans))==1)) stop("Vector lengths not correct")
  if (length(color)==1 & length(trans)>1) color <- rep(color,length(trans))
  if (length(trans)==1 & length(color)>1) trans <- rep(trans,length(color))
  
  num2hex <- function(x)
  {
    hex <- unlist(strsplit("0123456789ABCDEF",split=""))
    return(paste(hex[(x-x%%16)/16+1],hex[x%%16+1],sep=""))
  }
  rgb <- rbind(col2rgb(color),trans)
  res <- paste("#",apply(apply(rgb,2,num2hex),2,paste,collapse=""),sep="")
  return(res)
}
msxakk89/dat documentation built on Aug. 3, 2020, 6:39 p.m.