Jump to content

Julia set: Difference between revisions

→‎{{header|Perl 6}}: Small tweaks, finishes in 1/3 the time, same output
m (→‎{{header|C}}: Remove vanity tags)
(→‎{{header|Perl 6}}: Small tweaks, finishes in 1/3 the time, same output)
Line 1,174:
 
sub julia ( $png ) {
for ^$w .race.map: -> $x {
for ^$h -> $y {
my $z = Complex.new(($x - $w / 2) / $w * 3, ($y - $h / 2) / $h * 2);
Line 1,181:
$z = $z*$z + $c;
}
$png.set: $x, $y, |hsv2rgb($i / $maxIter * 360, 1, ?$i).reverse;
}
}
}
 
sub hsv2rgb ( $h, $s, $v ){ # inputs normalized 0-1
my $c = $v * $s;
my $x = $c * (1 - abs( (($h/60*6) % 2) - 1 ) );
my $m = $v - $c;
my ($r, $g, $b) = do given $h {
when 0..^60 (1/6) { $c, $x, 0 }
when 601/6..^120(1/3) { $x, $c, 0 }
when 1201/3..^180(1/2) { 0, $c, $x }
when 1801/2..^240(2/3) { 0, $x, $c }
when 2402/3..^300(5/6) { $x, 0, $c }
when 3005/6..^3601 { $c, 0, $x }
}
( $r, $g, $b ) = .map {: (($_*+$m) * 255).Int }, $r, $g, $b;
}</lang>
 
10,343

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.