Debian Codegraph @

R/adjust_hcl.R

raw
1 adjust_hcl <- function(col, h = 0, c = 0, l = 0, method = "relative", fixup = TRUE, maxchroma = TRUE)
2 {
3 ## method
4 method <- match.arg(method, c("relative", "absolute"))
5
6 ## number of colors
7 n <- max(c(length(col), length(h), length(c), length(l)))
8 if(length(col) != n) col <- rep_len(col, length.out = n)
9 if(length(h) != n) h <- rep_len(h, length.out = n)
10 if(length(c) != n) c <- rep_len(c, length.out = n)
11 if(length(l) != n) l <- rep_len(l, length.out = n)
12
13 ## handle prismatic colors class (essentially character + class attribute)
14 if(is.character(col) && inherits(col, "colors")) {
15 col <- as.character(col) ## workaround for prismatic colors class
16 prismatic <- TRUE
17 } else {
18 prismatic <- FALSE
19 }
20
21 ## col has to be hex code, otherwise col2rgb is used
22 if(is.character(col) &&
23 (all(substr(col, 1L, 1L) == "#") & all(nchar(col) %in% c(7L, 9L))))
24 {
25 ## extract alpha from hex (if any)
26 alpha <- substr(col, 8L, 9L)
27 ## retain only RGB in hex
28 col <- substr(col, 1L, 7L)
29 ## convert to colorspace::RGB
30 col <- hex2RGB(col)
31 } else {
32 col <- col2rgb(col, alpha = TRUE)
33 ## extract alpha values (if non-FF)
34 alpha <- format(as.hexmode(col[4L, ]), width = 2L, upper.case = TRUE)
35 alpha[alpha == "FF"] <- ""
36 ## retain only RGB
37 col <- sRGB(t(col[1L:3L, ])/255)
38 }
39
40 ## convert to HCL and remove chroma
41 col <- as(col, "polarLUV")
42 ## fix-up extreme luminance cases
43 col@coords[, "L"] <- pmin(100, pmax(0, col@coords[, "L"]))
44
45 ## transform coordinates
46 if(method == "relative") {
47 col@coords[, "H"] <- col@coords[, "H"] * (1 + h)
48 col@coords[, "C"] <- col@coords[, "C"] * (1 + c)
49 col@coords[, "L"] <- col@coords[, "L"] * (1 + l)
50 } else {
51 col@coords[, "H"] <- col@coords[, "H"] + h * 360
52 col@coords[, "C"] <- col@coords[, "C"] + c * 100
53 col@coords[, "L"] <- col@coords[, "L"] + l * 100
54 }
55 col@coords[, "C"] <- pmin(100, pmax(0, col@coords[, "C"]))
56 col@coords[, "L"] <- pmin(100, pmax(0, col@coords[, "L"]))
57
58 if(maxchroma) {
59 col@coords[, "C"] <- pmin(col@coords[, "C"], max_chroma(col@coords[, "H"], col@coords[, "L"]))
60 }
61
62 ## convert back to hex and add alpha and names again (if any)
63 col <- hex(col, fixup = fixup)
64 col[!is.na(col)] <- paste(col[!is.na(col)], alpha[!is.na(col)], sep = "")
65
66 ## add prismatic colors class again (if applicable)
67 if(prismatic) attr(col, "class") <- "colors"
68
69 return(col)
70 }
71
72
73 ## turn colors lighter or darker in either HCL or HLS space
74 lightdark <- function(col, amount = 0.1,
75 method = "relative", space = c("HLS", "HCL"), fixup = TRUE)
76 {
77 ## method
78 space <- match.arg(space, c("HLS", "HCL"))
79 method <- match.arg(method, c("relative", "absolute"))
80
81 ## number of colors
82 n <- max(c(length(col), length(amount)))
83 col <- rep_len(col, length.out = n)
84 amount <- rep_len(amount, length.out = n)
85
86 ## handle prismatic colors class (essentially character + class attribute)
87 if(is.character(col) && inherits(col, "colors")) {
88 col <- as.character(col) ## workaround for prismatic colors class
89 prismatic <- TRUE
90 } else {
91 prismatic <- FALSE
92 }
93
94 ## col has to be hex code, otherwise col2rgb is used
95 if(is.character(col) &&
96 (all(substr(col, 1L, 1L) == "#") & all(nchar(col) %in% c(7L, 9L))))
97 {
98 ## extract alpha from hex (if any)
99 alpha <- substr(col, 8L, 9L)
100 ## retain only RGB in hex
101 col <- substr(col, 1L, 7L)
102 ## convert to colorspace::RGB
103 col <- hex2RGB(col)
104 } else {
105 col <- col2rgb(col, alpha = TRUE)
106 ## extract alpha values (if non-FF)
107 alpha <- format(as.hexmode(col[4L, ]), width = 2L, upper.case = TRUE)
108 alpha[alpha == "FF"] <- ""
109 ## retain only RGB
110 col <- sRGB(t(col[1L:3L, ])/255)
111 }
112
113 if(space == "HCL") {
114 ## convert to HCL and remove chroma
115 col <- as(col, "polarLUV")
116 ## fix-up extreme luminance cases
117 col@coords[, "L"] <- pmin(100, pmax(0, col@coords[, "L"]))
118
119 ## transform luminance
120 Lold <- col@coords[, "L"]
121 col@coords[, "L"] <- if(method == "relative") {
122 Lold * (1 + amount)
123 } else {
124 Lold + amount * 100
125 }
126 col@coords[, "L"] <- pmin(100, pmax(0, col@coords[, "L"]))
127 ## transform chroma correspondingly (relative to maximum chroma possible)
128 col@coords[, "C"] <- col@coords[, "C"]/ceiling(max_chroma(col@coords[, "H"], Lold) + 1e-8) *
129 max_chroma(col@coords[, "H"], col@coords[, "L"], floor = TRUE)
130 col@coords[, "C"] <- pmin(100, pmax(0, col@coords[, "C"]))
131 } else {
132 col <- as(col, "HLS")
133 col@coords[, "L"] <- if(method == "relative") {
134 col@coords[, "L"] * (1 + amount)
135 } else {
136 col@coords[, "L"] + amount
137 }
138 col@coords[, "L"] <- pmin(1, pmax(0, col@coords[, "L"]))
139 }
140
141 ## convert back to hex and add alpha again (if any)
142 col <- hex(col, fixup = fixup)
143 col[!is.na(col)] <- paste(col[!is.na(col)], alpha[!is.na(col)], sep = "")
144
145 ## add prismatic colors class again (if applicable)
146 if(prismatic) attr(col, "class") <- "colors"
147
148 return(col)
149 }
150
151
152 if(FALSE) {
153 ## code
154 library("colorspace")
155 pal <- function(col, border = "light gray") {
156 n <- length(col)
157 plot(0, 0, type="n", xlim = c(0, 1), ylim = c(0, 1), axes = FALSE, xlab = "", ylab = "")
158 rect(0:(n-1)/n, 0, 1:n/n, 1, col = col, border = border)
159 }
160
161 ## fairly dark/colorful colors --> turn lighter
162 cl <- rainbow_hcl(5)
163
164 ## HLS vs. HCL --> HCL is much more balanced
165 par(mfrow = c(3, 2), mar = rep(0, 4), oma = c(0, 0, 2, 0))
166 pal(cl); mtext("HLS")
167 pal(cl); mtext("HCL")
168 pal(lightdark(cl, 0.15))
169 pal(lightdark(cl, 0.15, space = "HCL"))
170 pal(lightdark(cl, 0.30))
171 pal(lightdark(cl, 0.30, space = "HCL"))
172
173
174 ## fairly light colors --> turn darker
175 cl <- rainbow_hcl(5, l = 90, c = 35)
176
177 ## HLS vs. HCL --> HCL is much more balanced
178 par(mfrow = c(3, 2), mar = rep(0, 4), oma = c(0, 0, 2, 0))
179 pal(cl); mtext("HLS")
180 pal(cl); mtext("HCL")
181 pal(lightdark(cl, -0.15))
182 pal(lightdark(cl, -0.15, space = "HCL"))
183 pal(lightdark(cl, -0.30))
184 pal(lightdark(cl, -0.30, space = "HCL"))
185
186
187 ## fairly light colors --> turn darker
188 ## http://stackoverflow.com/questions/30219738/is-there-a-way-to-programmatically-darken-the-color-given-rgb-values
189 cl <- c("#CDE4F3","#E7F3D3","#F7F0C7","#EFCFE5","#D0D1E7")
190
191 ## HLS vs. HCL --> HCL becomes darker but not more colorful...
192 par(mfrow = c(3, 2), mar = rep(0, 4), oma = c(0, 0, 2, 0))
193 pal(cl); mtext("HLS")
194 pal(cl); mtext("HCL")
195 pal(lightdark(cl, -0.15))
196 pal(lightdark(cl, -0.15, space = "HCL"))
197 pal(lightdark(cl, -0.30))
198 pal(lightdark(cl, -0.30, space = "HCL"))
199
200 }
201
202 if ( FALSE ) {
203
204 # ----------------------------------------------------------------
205 # Development function to get multi-hue diverging color maps
206 # ----------------------------------------------------------------
207 multiverge_hcl <- function(n,h=c(10,100,230,290),l=60,lmax=90,fixup=FALSE) {
208
209 C <- seq(0, min(max_chroma(h,l)), length.out = n)
210 L <- seq(lmax, l, length.out = n)
211 cols <- matrix("NA",ncol=length(h),nrow=n)
212 for ( i in 1:ncol(cols) ) {
213 cols[,i] <- hex(polarLUV(H=h[i],C=C,L=L),fixup)
214 }
215 attr(cols,"H") <- h
216 attr(cols,"C") <- C
217 attr(cols,"L") <- L
218
219 cols
220 }
221
222 # ----------------------------------------------------------------
223 # Development function to show the color map properties
224 # ----------------------------------------------------------------
225 showcols <- function(cols) {
226 opar <- par(no.readonly=TRUE); on.exit(par(opar))
227 par(ask=TRUE)
228 par(mfrow=c(ncol(cols),1),mar=c(0,3,0,0),oma=rep(0,4),xaxt='n',yaxt='n')
229 for ( i in 1:ncol(cols) ) {
230 image(matrix(1:nrow(cols)),col=cols[,i])
231 mtext(side=2,attr(cols,"H")[i])
232 }
233
234 # Show space
235 h <- attr(cols,"H")
236 res <- matrix(NA,ncol=length(h),nrow=101)
237 for ( i in seq_along(h) ) {
238 names <- sprintf("%d-%d",round(h[i]),0:100)
239 res[,i] <- as.numeric(tab[names(tab) %in% names])
240 }
241 par(mar=c(4,4,2,1),xaxt='s',yaxt='s',mfrow=c(1,1),xaxs='i',yaxs='i')
242 plot(0,xlim=c(0,max(res)),ylim=c(0,100),type="n",main="Space Check",
243 xlab="Chroma", ylab="Luminance")
244 for ( i in 1:length(h) ) {
245 lines(res[,i],0:100,col=cols[nrow(cols),i])
246 }
247 points(attr(cols,'C'),attr(cols,'L'))
248 }
249
250 # ----------------------------------------------------------------
251 # A working set
252 # ----------------------------------------------------------------
253 h <- c(10,100,230,290)
254 l <- 50
255 lmax <- 90
256 cols <- multiverge_hcl(10,h=h,l=l,lmax=lmax)
257 showcols(cols)
258
259 # ----------------------------------------------------------------
260 # Fixup=FALSE, wherefore we have missing colors here (non-working
261 # example, even if a fixup would lead to quite good results)
262 # ----------------------------------------------------------------
263 h <- c(10,290)
264 l <- 70
265 lmax <- 99
266 cols <- multiverge_hcl(10,h=h,l=l,lmax=lmax)
267 showcols(cols)
268
269 }
270
271
272 lightdark2 <- function(col, amount = 0.1,
273 method = "relative", space = c("HLS", "HCL", "combined"), fixup = TRUE)
274 {
275 ## method
276 space <- match.arg(space, c("HLS", "HCL", "combined"))
277 method <- match.arg(method, c("relative", "absolute"))
278
279 ## number of colors
280 n <- max(c(length(col), length(amount)))
281 col <- rep_len(col, length.out = n)
282 amount <- rep_len(amount, length.out = n)
283
284 ## handle prismatic colors class (essentially character + class attribute)
285 if(is.character(col) && inherits(col, "colors")) {
286 col <- as.character(col) ## workaround for prismatic colors class
287 prismatic <- TRUE
288 } else {
289 prismatic <- FALSE
290 }
291
292 ## col has to be hex code, otherwise col2rgb is used
293 if(is.character(col) &&
294 (all(substr(col, 1L, 1L) == "#") & all(nchar(col) %in% c(7L, 9L))))
295 {
296 ## extract alpha from hex (if any)
297 alpha <- substr(col, 8L, 9L)
298 ## retain only RGB in hex
299 col <- substr(col, 1L, 7L)
300 ## convert to colorspace::RGB
301 col <- hex2RGB(col)
302 } else {
303 col <- col2rgb(col, alpha = TRUE)
304 ## extract alpha values (if non-FF)
305 alpha <- format(as.hexmode(col[4L, ]), width = 2L, upper.case = TRUE)
306 alpha[alpha == "FF"] <- ""
307 ## retain only RGB
308 col <- sRGB(t(col[1L:3L, ])/255)
309 }
310
311 if (space == "HCL") {
312 ## *** darkening/lightening in HCL space ***
313
314 ## convert to HCL and remove chroma
315 col <- as(col, "polarLUV")
316 ## fix-up extreme luminance cases
317 col@coords[, "L"] <- pmin(100, pmax(0, col@coords[, "L"]))
318
319 ## transform luminance
320 Lold <- col@coords[, "L"]
321 col@coords[, "L"] <- if(method == "relative") {
322 (amount >= 0) * (100 - (100 - Lold) * (1 - amount)) +
323 (amount < 0) * Lold * (1 + amount)
324 } else {
325 Lold + amount * 100
326 }
327 col@coords[, "L"] <- pmin(100, pmax(0, col@coords[, "L"]))
328
329 ## transform chroma correspondingly (relative to maximum chroma possible)
330 ## With the availability of the combined model, it seems better to not apply this adjustment here.
331 ## Lighened colors look better without it, and darkened colors look better under the combined model.
332 #col@coords[, "C"] <- col@coords[, "C"]/ceiling(max_chroma(col@coords[, "H"], Lold) + 1e-8) *
333 # max_chroma(col@coords[, "H"], col@coords[, "L"], floor = TRUE)
334 ## check that resulting chroma is within appropriate bounds
335 col@coords[, "C"] <- pmin(max_chroma(col@coords[, "H"], col@coords[, "L"], floor = TRUE),
336 pmax(0, col@coords[, "C"]))
337 }
338 else if (space == "HLS") {
339 ## *** darkening/lightening in HLS space ***
340
341 col <- as(col, "HLS")
342 col@coords[, "L"] <- if(method == "relative") {
343 (amount >= 0) * (1 - (1 - col@coords[, "L"]) * (1 - amount)) +
344 (amount < 0) * col@coords[, "L"] * (1 + amount)
345 } else {
346 col@coords[, "L"] + amount
347 }
348 col@coords[, "L"] <- pmin(1, pmax(0, col@coords[, "L"]))
349 } else {
350 ## *** darkening/lightening in combined space ***
351
352 colHLS <- as(col, "HLS")
353 colHLS@coords[, "L"] <- if(method == "relative") {
354 (amount >= 0) * (1 - (1 - colHLS@coords[, "L"]) * (1 - amount)) +
355 (amount < 0) * colHLS@coords[, "L"] * (1 + amount)
356 } else {
357 colHLS@coords[, "L"] + amount
358 }
359 colHLS@coords[, "L"] <- pmin(1, pmax(0, colHLS@coords[, "L"]))
360
361 colHLSHCL <- as(as(colHLS, "RGB"), "polarLUV")
362
363 ## convert to HCL
364 colHCL <- as(col, "polarLUV")
365 ## fix-up extreme luminance cases
366 colHCL@coords[, "L"] <- pmin(100, pmax(0, colHCL@coords[, "L"]))
367
368 ## transform luminance
369 Lold <- colHCL@coords[, "L"]
370 colHCL@coords[, "L"] <- if(method == "relative") {
371 (amount >= 0) * (100 - (100 - Lold) * (1 - amount)) +
372 (amount < 0) * Lold * (1 + amount)
373 } else {
374 Lold + amount * 100
375 }
376
377 #print(colHCL@coords[, "H"])
378 #print(colHLSHCL@coords[, "H"])
379
380 colHCL@coords[, "L"] <- pmin(100, pmax(0, colHCL@coords[, "L"]))
381 #colHCL@coords[, "H"] <- colHLSHCL@coords[, "H"]
382 colHCL@coords[, "C"] <- colHLSHCL@coords[, "C"]
383
384 ## transform chroma correspondingly (relative to maximum chroma possible)
385 colHCL@coords[, "C"] <- pmin(max_chroma(colHCL@coords[, "H"], colHCL@coords[, "L"], floor = TRUE), colHCL@coords[, "C"])
386 col <- colHCL
387 }
388
389 ## convert back to hex and add alpha again (if any)
390 col <- hex(col, fixup = fixup)
391 col[!is.na(col)] <- paste(col[!is.na(col)], alpha[!is.na(col)], sep = "")
392
393 ## add prismatic colors class again (if applicable)
394 if(prismatic) attr(col, "class") <- "colors"
395
396 return(col)
397 }
398
399
400 if(FALSE) {
401 ## code
402 library("colorspace")
403
404 ## convenience demo functions
405 wheel <- function(col, radius = 1, ...)
406 pie(rep(1, length(col)), col = col, radius = radius, ...)
407
408 pal <- function(col, border = "light gray") {
409 n <- length(col)
410 plot(0, 0, type="n", xlim = c(0, 1), ylim = c(0, 1), axes = FALSE, xlab = "", ylab = "")
411 rect(0:(n-1)/n, 0, 1:n/n, 1, col = col, border = border)
412 }
413
414
415 ## compare original & lightened colors
416 par(mar = rep(0, 4), mfrow = c(6, 3))
417 wheel(rainbow_hcl(12)); mtext("HLS")
418 wheel(rainbow_hcl(12)); mtext("HCL")
419 wheel(rainbow_hcl(12)); mtext("combined")
420 wheel(lightdark2(rainbow_hcl(12), amount = 0.2))
421 wheel(lightdark2(rainbow_hcl(12), amount = 0.2, space = "HCL"))
422 wheel(lightdark2(rainbow_hcl(12), amount = 0.2, space = "combined"))
423 wheel(lightdark2(rainbow_hcl(12), amount = 0.4))
424 wheel(lightdark2(rainbow_hcl(12), amount = 0.4, space = "HCL"))
425 wheel(lightdark2(rainbow_hcl(12), amount = 0.4, space = "combined"))
426 wheel(rainbow(12))
427 wheel(rainbow(12))
428 wheel(rainbow(12))
429 wheel(lightdark2(rainbow(12), amount = 0.2))
430 wheel(lightdark2(rainbow(12), amount = 0.2, space = "HCL"))
431 wheel(lightdark2(rainbow(12), amount = 0.2, space = "combined"))
432 wheel(lightdark2(rainbow(12), amount = 0.4))
433 wheel(lightdark2(rainbow(12), amount = 0.4, space = "HCL"))
434 wheel(lightdark2(rainbow(12), amount = 0.4, space = "combined"))
435
436 ## compare original & darkened colors
437 par(mar = rep(0, 4), mfrow = c(6, 3))
438 wheel(rainbow_hcl(12)); mtext("HLS")
439 wheel(rainbow_hcl(12)); mtext("HCL")
440 wheel(rainbow_hcl(12)); mtext("combined")
441 wheel(lightdark2(rainbow_hcl(12), amount = -0.2))
442 wheel(lightdark2(rainbow_hcl(12), amount = -0.2, space = "HCL"))
443 wheel(lightdark2(rainbow_hcl(12), amount = -0.2, space = "combined"))
444 wheel(lightdark2(rainbow_hcl(12), amount = -0.4))
445 wheel(lightdark2(rainbow_hcl(12), amount = -0.4, space = "HCL"))
446 wheel(lightdark2(rainbow_hcl(12), amount = -0.4, space = "combined"))
447 wheel(rainbow(12))
448 wheel(rainbow(12))
449 wheel(rainbow(12))
450 wheel(lightdark2(rainbow(12), amount = -0.2))
451 wheel(lightdark2(rainbow(12), amount = -0.2, space = "HCL"))
452 wheel(lightdark2(rainbow(12), amount = -0.2, space = "combined"))
453 wheel(lightdark2(rainbow(12), amount = -0.4))
454 wheel(lightdark2(rainbow(12), amount = -0.4, space = "HCL"))
455 wheel(lightdark2(rainbow(12), amount = -0.4, space = "combined"))
456
457
458
459 ## fairly dark/colorful colors --> turn lighter
460 cl <- rainbow_hcl(5)
461
462 ## HLS vs. HCL vs. combined --> HCL works best
463 par(mfrow = c(3, 3), mar = rep(0, 4), oma = c(0, 0, 2, 0))
464 pal(cl); mtext("HLS")
465 pal(cl); mtext("HCL")
466 pal(cl); mtext("combined")
467 pal(lightdark2(cl, 0.2))
468 pal(lightdark2(cl, 0.2, space = "HCL"))
469 pal(lightdark2(cl, 0.2, space = "combined"))
470 pal(lightdark2(cl, 0.4))
471 pal(lightdark2(cl, 0.4, space = "HCL"))
472 pal(lightdark2(cl, 0.4, space = "combined"))
473
474
475 ## fairly light colors --> turn darker
476 cl <- rainbow_hcl(5, l = 90, c = 35)
477
478 ## HLS vs. HCL vs. combined --> combined works best
479 par(mfrow = c(3, 3), mar = rep(0, 4), oma = c(0, 0, 2, 0))
480 pal(cl); mtext("HLS")
481 pal(cl); mtext("HCL")
482 pal(cl); mtext("combined")
483 pal(lightdark2(cl, -0.2))
484 pal(lightdark2(cl, -0.2, space = "HCL"))
485 pal(lightdark2(cl, -0.2, space = "combined"))
486 pal(lightdark2(cl, -0.4))
487 pal(lightdark2(cl, -0.4, space = "HCL"))
488 pal(lightdark2(cl, -0.4, space = "combined"))
489
490 ## fairly dark colors --> turn lighter
491 cl <- c("#E53B80", "#938102", "#069361", "#018EA1", "#C740EC")
492
493 ## HLS vs. HCL vs. combined --> HCL works best
494 par(mfrow = c(3, 3), mar = rep(0, 4), oma = c(0, 0, 2, 0))
495 pal(cl); mtext("HLS")
496 pal(cl); mtext("HCL")
497 pal(cl); mtext("combined")
498 pal(lightdark2(cl, 0.2))
499 pal(lightdark2(cl, 0.2, space = "HCL"))
500 pal(lightdark2(cl, 0.2, space = "combined"))
501 pal(lightdark2(cl, 0.4))
502 pal(lightdark2(cl, 0.4, space = "HCL"))
503 pal(lightdark2(cl, 0.4, space = "combined"))
504
505 ## fairly light colors --> turn darker
506 ## http://stackoverflow.com/questions/30219738/is-there-a-way-to-programmatically-darken-the-color-given-rgb-values
507 cl <- c("#CDE4F3","#E7F3D3","#F7F0C7","#EFCFE5","#D0D1E7")
508
509 ## HLS vs. HCL vs. combined --> HLS works best
510 par(mfrow = c(3, 3), mar = rep(0, 4), oma = c(0, 0, 2, 0))
511 pal(cl); mtext("HLS")
512 pal(cl); mtext("HCL")
513 pal(cl); mtext("combined")
514 pal(lightdark2(cl, -0.2))
515 pal(lightdark2(cl, -0.2, space = "HCL"))
516 pal(lightdark2(cl, -0.2, space = "combined"))
517 pal(lightdark2(cl, -0.4))
518 pal(lightdark2(cl, -0.4, space = "HCL"))
519 pal(lightdark2(cl, -0.4, space = "combined"))
520
521 ## moderately dark colors --> turn lighter
522 ## HLS vs. HCL vs. combined --> HCL works best
523 cl <- c("#61A9D9", "#ADD668", "#E6D152", "#CE6BAF", "#797CBA")
524 par(mfrow = c(3, 3), mar = rep(0, 4), oma = c(0, 0, 2, 0))
525 pal(cl); mtext("HLS")
526 pal(cl); mtext("HCL")
527 pal(cl); mtext("combined")
528 pal(lightdark2(cl, 0.2))
529 pal(lightdark2(cl, 0.2, space = "HCL"))
530 pal(lightdark2(cl, 0.2, space = "combined"))
531 pal(lightdark2(cl, 0.4))
532 pal(lightdark2(cl, 0.4, space = "HCL"))
533 pal(lightdark2(cl, 0.4, space = "combined"))
534
535 ## moderately dark colors --> turn lighter, test additive model
536 ## HLS vs. HCL vs. combined --> HCL works best
537 cl <- c("#61A9D9", "#ADD668", "#E6D152", "#CE6BAF", "#797CBA")
538 par(mfrow = c(3, 3), mar = rep(0, 4), oma = c(0, 0, 2, 0))
539 pal(cl); mtext("HLS")
540 pal(cl); mtext("HCL")
541 pal(cl); mtext("combined")
542 pal(lightdark2(cl, 0.1, method = "absolute"))
543 pal(lightdark2(cl, 0.1, method = "absolute", space = "HCL"))
544 pal(lightdark2(cl, 0.1, method = "absolute", space = "combined"))
545 pal(lightdark2(cl, 0.2, method = "absolute"))
546 pal(lightdark2(cl, 0.2, method = "absolute", space = "HCL"))
547 pal(lightdark2(cl, 0.2, method = "absolute", space = "combined"))
548 }