in reply to Generating Visually Distinct Colors
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!).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Generating Visually Distinct Colors
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 | |
|
Re^2: Generating Visually Distinct Colors
by Roy Johnson (Monsignor) on Mar 22, 2005 at 21:32 UTC |