in reply to Re: Browser safe colors :)
in thread HTML RGB hex color

Hm, define “like colors” and “together” ;-)

--
AltBlue.

Replies are listed 'Best First'.
Re^3: Browser safe colors :)
by slloyd (Hermit) on Apr 24, 2005 at 05:41 UTC
    "Like colors" would be to put the blues together and the reds together, and so forth. Your current script create four sets of like colors instead of one.. In other words.. is it possible to generate the colors to follow the color spectrum so that all like colors are grouped together (greens with greens, reds with reds, etc.)?

      Here is some example on how to generate the "R/G/B-ish" lists:

      #!/usr/bin/perl -Twl use strict; my @SAFE = qw(0 51 102 153 204 255); my @RGB = ([RED => 0], [GREEN => 1], [BLUE => 2]); sub get_set {grep { $_ >= $_[0] && $_ < $_[1] } @SAFE} sub dec_hex {map {sprintf "%02x", $_} @_} sub permute { my $last = pop @_; return map [$_], @$last if(!@_); return map { my $left = $_; map [@$left, $_], @$last } permute(@_); } foreach my $R (@RGB) { print $/, $R->[0], 'ish:'; foreach my $t (get_set(51, 256)) { my @clrs = get_set(0, $t); foreach (permute(\@clrs, \@clrs)) { my @tuple = @$_; splice(@tuple, $R->[1], 0, $t); print '#', dec_hex(@tuple); } } } print $/, 'GRAYish:'; print '#', dec_hex(($_)x3) for @SAFE;

      Ahem. This would mean to really plug in some real graphics knowledge (some maths model for the “color spectrum” and things like that), area that I don't happen to know too much about. ;-)

      Some fellow monks asked about related things getting back information that could also help you: RGB values and color name, color selection image map, ... (search for color, RGB, etc)

      OTOH, if all that you want is "red", "green" and "blue", than I suppose you could use a combinations-like algorithm, e.g. "redish" is every tuple that has the first term numerically bigger by both others two:
      #996633: 99>66 && 99 > 33 => it is "redish"