Julia set: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (→{{header|Perl 6}}: more simplification, DRY) |
Thundergnat (talk | contribs) m (→{{header|Perl 6}}: remove a bunch of superstitious parenthesis) |
||
Line 121: | Line 121: | ||
<lang perl6>use Image::PNG::Portable; |
<lang perl6>use Image::PNG::Portable; |
||
my ($w, $h) = |
my ($w, $h) = 800, 600; |
||
my $out = Image::PNG::Portable.new: :width($w), :height($h); |
my $out = Image::PNG::Portable.new: :width($w), :height($h); |
||
Line 127: | Line 127: | ||
my $maxIter = 255; |
my $maxIter = 255; |
||
my ($cX, $cY) = |
my ($cX, $cY) = -0.7, 0.27015; |
||
julia($out); |
julia($out); |
||
Line 140: | Line 140: | ||
my $i = $maxIter; |
my $i = $maxIter; |
||
while $zx² + $zy² < 4 and --$i { |
while $zx² + $zy² < 4 and --$i { |
||
($zy, $zx) = |
($zy, $zx) = 2 * $zx * $zy + $cY, $zx² - $zy² + $cX; |
||
} |
} |
||
$png.set |
$png.set: $x, $y, |hsv2rgb($i / $maxIter * 360, 1, ?$i).reverse; |
||
} |
} |
||
} |
} |
||
Line 152: | Line 152: | ||
my $m = $v - $c; |
my $m = $v - $c; |
||
my ($r, $g, $b) = do given $h { |
my ($r, $g, $b) = do given $h { |
||
when 0..^60 { |
when 0..^60 { $c, $x, 0 } |
||
when 60..^120 { |
when 60..^120 { $x, $c, 0 } |
||
when 120..^180 { |
when 120..^180 { 0, $c, $x } |
||
when 180..^240 { |
when 180..^240 { 0, $x, $c } |
||
when 240..^300 { |
when 240..^300 { $x, 0, $c } |
||
when 300..^360 { |
when 300..^360 { $c, 0, $x } |
||
} |
} |
||
( $r, $g, $b ) = map { (($_+$m) * 255).Int }, $r, $g, $b; |
( $r, $g, $b ) = map { (($_+$m) * 255).Int }, $r, $g, $b; |