Dear Thomas,

This seems simpler than the solution that I used, so I'll give it a
try.

Thanks,
 John

On Tue, 22 May 2007 09:01:01 -0700 (PDT)
 Thomas Lumley <[EMAIL PROTECTED]> wrote:
> On Mon, 21 May 2007, John Fox wrote:
> >
> > In retrospect, I didn't specify the problem clearly: What I want to
> be able
> > to do is to place text on a background of arbitrary (but known RGB)
> colour
> > so that the text is legible. I guess that this is better described
> as a
> > "contrasting" than a "complementary" colour.
> 
> Since luminance contrasts are necessary and sufficient for readable
> text, you could use white for dark colors and black for light colors.
> 
> Luminance is roughly proportional to  0.2*(R^2.4)+0.6*(G^2.4),
> suggesting something like
> 
> lightdark<-function (color)
> {
>      rgb <- col2rgb(color)/255
>      L <- c(0.2, 0.6, 0) %*% rgb
>      ifelse(L >= 0.2, "#000060", "#FFFFA0")
> }
> 
> This uses a pale yellow for dark backgrounds and a dark blue for
> light backgrounds, and it seems to work reasonably well.
> 
>       -thomas

--------------------------------
John Fox
Department of Sociology
McMaster University
Hamilton, Ontario, Canada
http://socserv.mcmaster.ca/jfox/

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to