
R version 4.2.0 (2022-04-22) -- "Vigorous Calisthenics"
Copyright (C) 2022 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library("colorspace")
> 
> 
> ## convert a hex color
> simulate_cvd("#33ab20", tritanomaly_cvd["6"][[1]])
[1] "#23A968"
> 
> ## convert a named color
> simulate_cvd("red", deutanomaly_cvd["8"][[1]])
[1] "#AE8800"
> 
> ## convert a mixed vector (hex and named)
> simulate_cvd(c("green", "#ffc0cb"), protanomaly_cvd["8"][[1]])
[1] "#F6E800" "#D1C9CB"
> 
> ## white and black unchanged
> ## simulate_cvd(c("white", "black"), deutanomaly_cvd["2"][[1]])
> 
> 
> ## make sure that different sequences of conversions lead to equivalent output
> 
> ## vector of different hex colors
> col_hex <- c(rainbow(33), sequential_hcl(33, "Plasma"), sequential_hcl(33, "YlGnBu"))
> 
> ## corresponding color object in sRGB and linear RGB
> col_srgb <- hex2RGB(col_hex)
> col_rgb <- as(col_srgb, "RGB")
> 
> ## corresponding RGB coordinates in 0-255
> mat_srgb <- coords(col_srgb) * 255
> mat_rgb <- coords(col_rgb) * 255
> 
> ## protan transformation in linear RGB (default) and gamma-corrected sRGB (linear = FALSE)
> identical(protan(col_hex),                 hex(protan(col_srgb)))
[1] TRUE
> identical(protan(col_hex),                 hex(protan(col_rgb)))
[1] TRUE
> identical(protan(col_hex),                 hex(RGB(protan(mat_rgb)/255)))
[1] TRUE
> identical(protan(col_hex, linear = FALSE), hex(protan(col_srgb, linear = FALSE)))
[1] TRUE
> identical(protan(col_hex, linear = FALSE), hex(protan(col_rgb, linear = FALSE)))
[1] TRUE
> identical(protan(col_hex, linear = FALSE), hex(sRGB(protan(mat_srgb)/255)))
[1] TRUE
> 
> proc.time()
   user  system elapsed 
  0.179   0.016   0.185 
