convert R color to HSL color matrix

col2hsl(x, ...)

Arguments

x

character vector with R compatible colors.

...

additional arguments are ignored.

Details

This function takes an R color and converts to an HSL matrix, using the farver package farver::decode_colour() the colorspace package, and RGB and polarLUV functions. It is also used to maintain alpha transparency, to enable interconversion via other color manipulation functions as well.

When model="hsl" this function uses farver::decode_colour() and bypasses colorspace. In future the colorspace dependency will likely be removed in favor of using farver. In any event, model="hsl" is equivalent to using model="polarLUV" and fixup=TRUE, except that it should be much faster.

Examples

x <- c("#FF000044", "#FF0000", "firebrick");
names(x) <- x;
showColors(x)

xhsl <- col2hsl(x)
xhsl
#>         #FF000044 #FF0000 firebrick
#> H       0.0000000       0   0.00000
#> S     100.0000000     100  67.92453
#> L      50.0000000      50  41.56863
#> alpha   0.2666667       1   1.00000

xhex <- hsl2col(xhsl)
showColors(list(x=x,
   xhex=xhex),
   groupCellnotes=FALSE)


opar <- par("mfrow"=c(4, 4));
on.exit(par(opar));
for (H in seq(from=0, to=360, length.out=17)[-17]) {
S <- 75;
Lseq <- seq(from=15, to=95, by=10);
hsl_gradient <- hsl2col(
   H=H,
   S=85,
   L=Lseq);
hcl_gradient <- hcl2col(
   H=H,
   C=85,
   L=Lseq);
names(hsl_gradient) <- Lseq;
names(hcl_gradient) <- Lseq;
showColors(
   list(
      hsl=hsl_gradient,
      hcl=hcl_gradient),
   main=paste0("Hue: ", round(H),
      "\nSat: ", S,
      "\nLum: (as labeled)"),
   groupCellnotes=FALSE)
}