Color wheel: Difference between revisions

Content added Content deleted
(→‎{{header|Perl 6}}: minor teaks, half the run time, same output)
m (→‎{{header|Perl 6}}: more efficient color space conversion)
Line 224: Line 224:
}
}


sub hsv2rgb ( $h, $s, $v ){ # inputs normalized 0-1
sub hsv2rgb ( $h, $s, $v ){
my $c = $v * $s;
my $c = $v * $s;
my $x = $c * (1 - abs( (($h*6) % 2) - 1 ) );
my $x = $c * (1 - abs( (($h*6) % 2) - 1 ) );
my $m = $v - $c;
my $m = $v - $c;
my ($r, $g, $b) = do given $h {
(do given $h {
when 0..^(1/6) { $c, $x, 0 }
when 0..^1/6 { $c, $x, 0 }
when 1/6..^(1/3) { $x, $c, 0 }
when 1/6..^1/3 { $x, $c, 0 }
when 1/3..^(1/2) { 0, $c, $x }
when 1/3..^1/2 { 0, $c, $x }
when 1/2..^(2/3) { 0, $x, $c }
when 1/2..^2/3 { 0, $x, $c }
when 2/3..^(5/6) { $x, 0, $c }
when 2/3..^5/6 { $x, 0, $c }
when 5/6..1 { $c, 0, $x }
when 5/6..1 { $c, 0, $x }
} ).map: ((*+$m) * 255).Int
}
( $r, $g, $b ).map: ((*+$m) * 255).Int
}</lang>
}</lang>