From: Felix Lee <flee@teleport.com>
Subject: Re: HTML foreground and background colors being the same... poll time!
Date: Thu, 03 Dec 1998 21:31:13 -0800 [thread overview]
Message-ID: <199812040531.AAA18464@sclp3.sclp.com> (raw)
In-Reply-To: <877lw8og9o.fsf@lolo.cybercable.fr> on 04 Dec 1998 01:19:31 GMT.
this is a tcl function I've been using for choosing
contrasting colors. it's not perfect (like, it tends to
think similar greens have more contrast than they do), but
it does a good job most of the time, especially if you're
only interested in choosing between very different colors
like white and black.
proc color/contrasting {w color {colors {black white}}} {
##
## Returns the color in $colors that most contrasts with
## $color in window $w. Currently, just looks at luminance.
set y0 [color/luminance $w $color]
set best $color
set dist 0
foreach c $colors {
set y [color/luminance $w $c]
set d [expr {abs($y - $y0)}]
if {$dist < $d} {
set best $c
set dist $d
}
}
return $best
}
proc color/luminance {w color} {
##
## Returns the (YIQ-model) luminance of $color in window $w.
set* {r g b} [winfo rgb $w $color]
expr {.299 * $r / 65535 + .587 * $g / 65535 + .114 * $b / 65535}
}
proc set* {names values} {
foreach name $names value $values {
upvar $name var
set var $value
}
}
prev parent reply other threads:[~1998-12-04 5:31 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-12-03 14:00 William M. Perry
1998-12-03 14:26 ` Hrvoje Niksic
1998-12-03 14:37 ` Didier Verna
1998-12-03 14:44 ` Hrvoje Niksic
1998-12-03 14:54 ` Colin Rafferty
1998-12-03 16:08 ` Ken McGlothlen
1998-12-03 14:56 ` Bill White
1998-12-03 16:43 ` Wes Hardaker
1998-12-03 18:49 ` Matt Armstrong
1998-12-09 16:06 ` William M. Perry
1998-12-04 1:19 ` Laurent Martelli
1998-12-04 5:31 ` Felix Lee [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=199812040531.AAA18464@sclp3.sclp.com \
--to=flee@teleport.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).