in reply to Generating Visually Distinct Colors
and then I wanted to use a single loop and came up with this:sub my_gdc { use POSIX 'ceil'; my $n = shift; my $discrete = ceil($n ** (1/3)); my @colors; GENERATE: for my $r (0..$discrete-1) { for my $g (0..$discrete-1) { for my $b (0..$discrete-1) { push @colors, [map {1-$_/$discrete} $r, $g, $b]; last GENERATE if @colors >= $n; } } } \@colors; }
sub my_gdc1 { use POSIX 'ceil'; my $n = shift; my $discrete = ceil($n ** (1/3)); my @colors = ([1,1,1]); for my $i (1..$n-1) { push @colors, [map {1-($_%$discrete)/$discrete} $i/($discrete**2), $i/$discrete, $i]; } \@colors; }
|
|---|