Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Making a color brighter

12 views
Skip to first unread message

im.goo...@googlemail.com

unread,
Feb 8, 2008, 3:17:38 PM2/8/08
to
Hi,

i need a proc that makes colors (eg. #FF7200) 10 percent brighter.

This is my try:
----------------------------
proc brighter {col} {
foreach {r g b} [winfo rgb . $col] {break}
set r [expr int($r/100.0*110)]
set g [expr int($g/100.0*110)]
set b [expr int($b/100.0*110)]
set ncol [format "#%02x%02x%02x" $r $g $b]
return $ncol
}
----------------------------

Sometimes the proc works, but sometimes it returns al color like:
#111707b0c00 it's too long, so i can't use it with Tk.

What can i do to get "correct" colors, i can use in Tk??

Thanx for help!

Donald G Porter

unread,
Feb 8, 2008, 3:21:17 PM2/8/08
to
im.goo...@googlemail.com wrote:

> set r [expr int($r/100.0*110)]

set r [expr {min(int($r/100.0*110), 255)}]

--
| Don Porter Mathematical and Computational Sciences Division |
| donald...@nist.gov Information Technology Laboratory |
| http://math.nist.gov/~DPorter/ NIST |
|______________________________________________________________________|

Frank Ranner

unread,
Feb 8, 2008, 11:02:52 PM2/8/08
to

You can convert the colours from rgb to hsv, multiply v by 1.1 with a max
value of 1.0, then convert back to rgb.

The algorithms are easily found - this page has a good explanation
along with example code in basic.

http://www.mandelbrot-dazibao.com/HSV/HSV.htm

This page has tcl code: http://wiki.tcl.tk/19711

Of course the end result may be the same as your code! You can use the
Gimp to play with color settings. Simply click on the color selector and
you can manipulate the rgb and hsv sliders.

regards,

Frank Ranner

keithv

unread,
Feb 8, 2008, 11:57:36 PM2/8/08
to
On Feb 8, 3:17 pm, im.good.p...@googlemail.com wrote:

> i need a proc that makes colors

> 10 percent brighter.

In the file palette.tcl in the tk distribution
is a function called ::tk::Darken that does:
# Given a color name, computes a new color
# value that darkens (or brightens) the given
# color by a given percent.

It's not an officially supported function so
you'd be best off to copy the function to your
program.

Keith


0 new messages