brighten

brighten (color) (factor)
returns brightened color in format #rrrrggggbbbb

proc brighten {color factor} {
  lassign [rgb $color] r g b
  #
  if {$factor < 1} then {
    # darker
    set r3 [round [* $r $factor]]
    set g3 [round [* $g $factor]]
    set b3 [round [* $b $factor]]
  } else {
    # brighter
    set f1 [- 2 $factor]
    #
    set r1 [- 65535 $r]
    set g1 [- 65535 $g]
    set b1 [- 65535 $b]
    #
    set r2 [round [* $r1 $f1]]
    set g2 [round [* $g1 $f1]]
    set b2 [round [* $b1 $f1]]
    #
    set r3 [- 65535 $r2]
    set g3 [- 65535 $g2]
    set b3 [- 65535 $b2]
  }
  string cat # [format %04x $r3] [format %04x $g3] [format %04x $b3]
}

© Wolf-Dieter Busch | Home | Sitemap | Urheber | A-Z