Debian Codegraph @

tests/cvd.Rout.save

raw
1
2 R version 4.2.0 (2022-04-22) -- "Vigorous Calisthenics"
3 Copyright (C) 2022 The R Foundation for Statistical Computing
4 Platform: x86_64-pc-linux-gnu (64-bit)
5
6 R is free software and comes with ABSOLUTELY NO WARRANTY.
7 You are welcome to redistribute it under certain conditions.
8 Type 'license()' or 'licence()' for distribution details.
9
10 R is a collaborative project with many contributors.
11 Type 'contributors()' for more information and
12 'citation()' on how to cite R or R packages in publications.
13
14 Type 'demo()' for some demos, 'help()' for on-line help, or
15 'help.start()' for an HTML browser interface to help.
16 Type 'q()' to quit R.
17
18 > library("colorspace")
19 >
20 >
21 > ## convert a hex color
22 > simulate_cvd("#33ab20", tritanomaly_cvd["6"][[1]])
23 [1] "#23A968"
24 >
25 > ## convert a named color
26 > simulate_cvd("red", deutanomaly_cvd["8"][[1]])
27 [1] "#AE8800"
28 >
29 > ## convert a mixed vector (hex and named)
30 > simulate_cvd(c("green", "#ffc0cb"), protanomaly_cvd["8"][[1]])
31 [1] "#F6E800" "#D1C9CB"
32 >
33 > ## white and black unchanged
34 > ## simulate_cvd(c("white", "black"), deutanomaly_cvd["2"][[1]])
35 >
36 >
37 > ## make sure that different sequences of conversions lead to equivalent output
38 >
39 > ## vector of different hex colors
40 > col_hex <- c(rainbow(33), sequential_hcl(33, "Plasma"), sequential_hcl(33, "YlGnBu"))
41 >
42 > ## corresponding color object in sRGB and linear RGB
43 > col_srgb <- hex2RGB(col_hex)
44 > col_rgb <- as(col_srgb, "RGB")
45 >
46 > ## corresponding RGB coordinates in 0-255
47 > mat_srgb <- coords(col_srgb) * 255
48 > mat_rgb <- coords(col_rgb) * 255
49 >
50 > ## protan transformation in linear RGB (default) and gamma-corrected sRGB (linear = FALSE)
51 > identical(protan(col_hex), hex(protan(col_srgb)))
52 [1] TRUE
53 > identical(protan(col_hex), hex(protan(col_rgb)))
54 [1] TRUE
55 > identical(protan(col_hex), hex(RGB(protan(mat_rgb)/255)))
56 [1] TRUE
57 > identical(protan(col_hex, linear = FALSE), hex(protan(col_srgb, linear = FALSE)))
58 [1] TRUE
59 > identical(protan(col_hex, linear = FALSE), hex(protan(col_rgb, linear = FALSE)))
60 [1] TRUE
61 > identical(protan(col_hex, linear = FALSE), hex(sRGB(protan(mat_srgb)/255)))
62 [1] TRUE
63 >
64 > proc.time()
65 user system elapsed
66 0.179 0.016 0.185