Julia set: Difference between revisions
Content added Content deleted
m (→{{header|Perl}}: added image) |
Thundergnat (talk | contribs) m (→{{header|Perl 6}}: Add Perl 6 example) |
||
Line 115: | Line 115: | ||
$img->write(file => 'julia_set.png');</lang> |
$img->write(file => 'julia_set.png');</lang> |
||
=={{header|Perl 6}}== |
|||
[[File:Julia-set-perl6.png|250px|thumb|right]] |
|||
{{trans|Perl}} with the pallette swapped, just because. |
|||
{{works with|Rakudo|2016.03}} |
|||
<lang perl6>use Image::PNG::Portable; |
|||
my ($w, $h) = (800, 600); |
|||
my $out = Image::PNG::Portable.new: :width($w), :height($h); |
|||
my $maxIter = 255; |
|||
my ($cX, $cY) = (-0.7, 0.27015); |
|||
julia($out); |
|||
$out.write: 'Julia-set-perl6.png'; |
|||
sub julia ( $png ) { |
|||
for ^$w -> $x { |
|||
for ^$h -> $y { |
|||
my $zx = (1.5 * ($x - $w / 2) / (0.5 * $w)); |
|||
my $zy = (($y - $h / 2) / (0.5 * $h)); |
|||
my $i = $maxIter; |
|||
while ($zx² + $zy² < 4 and $i > 1) { |
|||
($zy, $zx) = (2.0 * $zx * $zy + $cY, $zx² - $zy² + $cX); |
|||
$i--; |
|||
} |
|||
$png.set( $x, $y, |hsv2rgb($i / $maxIter * 360, 1, $i > 1 ?? 1 !! 0) ); |
|||
} |
|||
} |
|||
} |
|||
sub hsv2rgb ( $h, $s, $v ){ |
|||
my $c = $v * $s; |
|||
my $x = $c * (1 - abs( (($h/60) % 2) - 1 ) ); |
|||
my $m = $v - $c; |
|||
my ($r, $g, $b); |
|||
given $h { |
|||
when 0..^60 { ($r, $g, $b) = ($c, $x, 0) } |
|||
when 60..^120 { ($r, $g, $b) = ($x, $c, 0) } |
|||
when 120..^180 { ($r, $g, $b) = (0, $c, $x) } |
|||
when 180..^240 { ($r, $g, $b) = (0, $x, $c) } |
|||
when 240..^300 { ($r, $g, $b) = ($x, 0, $c) } |
|||
when 300..^360 { ($r, $g, $b) = ($c, 0, $x) } |
|||
} |
|||
( $r, $g, $b ) = map { (($_+$m) * 255).Int }, $r, $g, $b; |
|||
return $b, $g, $r; |
|||
}</lang> |
|||
=={{header|zkl}}== |
=={{header|zkl}}== |