User Tools

Site Tools


anadat:cs:fun:darken
# funkce na automaticke ztmaveni (nebo zesvetleni) barvy.
# udelano z funkce colortools::col2HSV
 
darken<- function (color, okolik) 
{
  rgb_col = col2rgb(color)
  hsv_col = rgb2hsv(rgb_col)
  if (length(color) == 1) {
    hue = hsv_col[1]
    sat = hsv_col[2]
    val = ifelse((hsv_col[3]-okolik) >= 0 & (hsv_col[3]-okolik) <= 1, hsv_col[3]-okolik, 
                 ifelse((hsv_col[3]-okolik) < 0, 0, 1))
    hex_col = hsv(hue, sat, val)
  }
  if (length(color) > 1) {
    hex_col = rep("", length(color))
    for (j in 1:length(color)) {
      hex_col[j] = hsv(hsv_col[1, j], hsv_col[2, j], 
                       ifelse((hsv_col[3, j]-okolik) >= 0 & (hsv_col[3, j]-okolik) <= 1, hsv_col[3, j]-okolik, 
                              ifelse((hsv_col[3, j]-okolik) < 0, 0, 1)))
    }
  }
  hex_col
}
anadat/cs/fun/darken.txt · Last modified: 2017/04/09 11:37 by vitek