From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/19647 Path: main.gmane.org!not-for-mail From: Felix Lee Newsgroups: gmane.emacs.gnus.general Subject: Re: HTML foreground and background colors being the same... poll time! Date: Thu, 03 Dec 1998 21:31:13 -0800 Sender: owner-ding@hpc.uh.edu Message-ID: <199812040531.AAA18464@sclp3.sclp.com> References: <877lw8og9o.fsf@lolo.cybercable.fr> NNTP-Posting-Host: coloc-standby.netfonds.no X-Trace: main.gmane.org 1035157959 12668 80.91.224.250 (20 Oct 2002 23:52:39 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Sun, 20 Oct 2002 23:52:39 +0000 (UTC) Return-Path: Original-Received: from gizmo.hpc.uh.edu (gizmo.hpc.uh.edu [129.7.102.31]) by sclp3.sclp.com (8.8.5/8.8.5) with ESMTP id AAA18486 for ; Fri, 4 Dec 1998 00:33:01 -0500 (EST) Original-Received: from sina.hpc.uh.edu (lists@sina.hpc.uh.edu [129.7.3.5]) by gizmo.hpc.uh.edu (8.9.1/8.9.1) with ESMTP id XAA31359; Thu, 3 Dec 1998 23:31:57 -0600 Original-Received: by sina.hpc.uh.edu (TLB v0.09a (1.20 tibbs 1996/10/09 22:03:07)); Thu, 03 Dec 1998 23:32:02 -0600 (CST) Original-Received: from sclp3.sclp.com (root@sclp3.sclp.com [204.252.123.139]) by sina.hpc.uh.edu (8.7.3/8.7.3) with ESMTP id XAA25615 for ; Thu, 3 Dec 1998 23:31:54 -0600 (CST) Original-Received: from mail1.teleport.com (mail1.teleport.com [192.108.254.26]) by sclp3.sclp.com (8.8.5/8.8.5) with SMTP id AAA18464 for ; Fri, 4 Dec 1998 00:31:46 -0500 (EST) Original-Received: (qmail 657 invoked from network); 4 Dec 1998 05:31:15 -0000 Original-Received: from pdx60-i48-09.teleport.com (HELO teleport.com) (204.202.168.23) by mail1.teleport.com with SMTP; 4 Dec 1998 05:31:15 -0000 Original-To: w3-beta@indiana.edu, ding@gnus.org In-reply-to: <877lw8og9o.fsf@lolo.cybercable.fr> on 04 Dec 1998 01:19:31 GMT. Precedence: list X-Majordomo: 1.94.jlt7 Original-Lines: 40 Xref: main.gmane.org gmane.emacs.gnus.general:19647 X-Report-Spam: http://spam.gmane.org/gmane.emacs.gnus.general:19647 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 } }