sub get_distinct_colors { use POSIX 'ceil'; my $n = shift; my $discrete = ceil($n ** (1/3)); my @vals = map 1 - (($_-1) / $discrete), 1 .. $discrete; my @colors; my ($r, $g, $b) = (0,0,0); for my $i (1 .. $n) { push @colors, [@vals[$r,$g,$b]]; if (++$b == $discrete) { if (++$g == $discrete) { $r = ($r + 1) % $discrete; $g = 0; } $b = 0; } } return \@colors; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Generating Visually Distinct Colors
by Roy Johnson (Monsignor) on Mar 22, 2005 at 04:52 UTC | |
Re: Generating Visually Distinct Colors
by iblech (Friar) on Mar 22, 2005 at 15:36 UTC | |
by japhy (Canon) on Mar 22, 2005 at 16:46 UTC | |
by polettix (Vicar) on Mar 22, 2005 at 18:47 UTC | |
by japhy (Canon) on Mar 22, 2005 at 21:06 UTC | |
by Roy Johnson (Monsignor) on Mar 22, 2005 at 21:32 UTC | |
Re: Generating Visually Distinct Colors
by sfink (Deacon) on Mar 22, 2005 at 18:07 UTC | |
by Roy Johnson (Monsignor) on Mar 22, 2005 at 18:33 UTC | |
Re: Generating Visually Distinct Colors
by cosimo (Hermit) on Mar 23, 2005 at 12:18 UTC | |
Re: Generating Visually Distinct Colors
by iblech (Friar) on Mar 23, 2005 at 13:39 UTC |