Version 0 of Picking a range of colors

Updated 2013-11-17 17:46:40 by dkf

DKF: I wanted to pick a range of colours (for indicating the priorities of Tcl bug reports , though you only get meaningful results there if you're a Tcl developer) yet the RGB color space is a tricky thing to work with. I wanted something like the range used by the old SourceForge tracker system, which ranged (approximately) from red through to purple. Getting a good perceptual sweep is non-trivial, but when dealing with how people perceive colors, a good rule is to use HSV rather than RGB. In particular, if I use code from HSV and RGB, I can do this:

set From "#ff462d"
set To "#a394c6"
lassign [rgbToHsv {*}[scan $From "#%2x%2x%2x"]] from(h) from(s) from(v)
lassign [rgbToHsv {*}[scan $To "#%2x%2x%2x"]] to(h) to(s) to(v)
foreach c {h s v} {set step($c) [expr {($to($c) - $from($c)) / 8.}]}
for {array set col [array get from];set i 0} {$i<=8} {incr i} {
    puts [format #%02x%02x%02x {*}[hsvToRgb $col(h) $col(s) $col(v)]]
    foreach c {h s v} {set col($c) [expr {$col($c) + $step($c)}]} 
}

Which produces this output:

#ff462d
#f8b53d
#d6f14d
#88ea5b
#69e382
#75dbc0
#81bfd4
#8b9acd
#a394c6

It's not perfect, as it doesn't take into account the different visual acuity of the human eye in different color channels, but it produces a reasonably pleasing result.