proc extractColor color if scan color 2x 2x 2x red blue green return l

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
proc extractColor {color} {
if {[scan $color "#%2x%2x%2x" red blue green] == 3} {
return [list $red $blue $green]
}
return {}
}
# puts [extractColor #1A3FAB]
proc packColor {red blue green} {
return [format "#%2x%2x%2x" $red $blue $green]
}
# puts [packColor 255 255 255]
proc calcColor {r g b brightPnc} {
return [list [expr round($r * ($brightPnc / 100.0) * 0.3) % 255] \
[expr round($g * ($brightPnc / 100.0) * 0.59) % 255] \
[expr round($b * ($brightPnc / 100.0) * 0.11) % 255]]
}
# puts [packColor {*}[calcColor {*}[extractColor "#66AC2E"] 30]]