| 1 |
library("colorspace") |
| 2 |
|
| 3 |
|
| 4 |
## convert a hex color |
| 5 |
simulate_cvd("#33ab20", tritanomaly_cvd["6"][[1]]) |
| 6 |
|
| 7 |
## convert a named color |
| 8 |
simulate_cvd("red", deutanomaly_cvd["8"][[1]]) |
| 9 |
|
| 10 |
## convert a mixed vector (hex and named) |
| 11 |
simulate_cvd(c("green", "#ffc0cb"), protanomaly_cvd["8"][[1]]) |
| 12 |
|
| 13 |
## white and black unchanged |
| 14 |
## simulate_cvd(c("white", "black"), deutanomaly_cvd["2"][[1]]) |
| 15 |
|
| 16 |
|
| 17 |
## make sure that different sequences of conversions lead to equivalent output |
| 18 |
|
| 19 |
## vector of different hex colors |
| 20 |
col_hex <- c(rainbow(33), sequential_hcl(33, "Plasma"), sequential_hcl(33, "YlGnBu")) |
| 21 |
|
| 22 |
## corresponding color object in sRGB and linear RGB |
| 23 |
col_srgb <- hex2RGB(col_hex) |
| 24 |
col_rgb <- as(col_srgb, "RGB") |
| 25 |
|
| 26 |
## corresponding RGB coordinates in 0-255 |
| 27 |
mat_srgb <- coords(col_srgb) * 255 |
| 28 |
mat_rgb <- coords(col_rgb) * 255 |
| 29 |
|
| 30 |
## protan transformation in linear RGB (default) and gamma-corrected sRGB (linear = FALSE) |
| 31 |
identical(protan(col_hex), hex(protan(col_srgb))) |
| 32 |
identical(protan(col_hex), hex(protan(col_rgb))) |
| 33 |
identical(protan(col_hex), hex(RGB(protan(mat_rgb)/255))) |
| 34 |
identical(protan(col_hex, linear = FALSE), hex(protan(col_srgb, linear = FALSE))) |
| 35 |
identical(protan(col_hex, linear = FALSE), hex(protan(col_rgb, linear = FALSE))) |
| 36 |
identical(protan(col_hex, linear = FALSE), hex(sRGB(protan(mat_srgb)/255))) |