Perl 6! :) (code slightly adapted to run under Pugs)
#!/usr/bin/perl6 use v6; # ceil() not yet implemented in Pugs sub ceil ($n) { int($n) + ($n > int($n) ?? 1 :: 0) } my $n = 10; my $discrete = ceil($n ** (1/3)); my $r = any 0..$discrete-1; my $g = any 0..$discrete-1; my $b = any 0..$discrete-1; # Now $r,$g,$b are Junctions containing all the possible values of # red/green/blue. $r = int( (1-$r/$discrete) * 255 ); $g = int( (1-$g/$discrete) * 255 ); $b = int( (1-$b/$discrete) * 255 ); # $color is a Junction containing all colors as "(red, green, blue)". my $color = "($r, $g, $b)"; # Finally, print $color. for $color -> $x { say $x }
Update: Hand-rolled ceil was wrong, fixed (thanks japhy!).
In reply to Re: Generating Visually Distinct Colors
by iblech
in thread Generating Visually Distinct Colors
by japhy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |