Mandelbrot set: Difference between revisions
→{{header|Raku}}: clarify $width and $height
(→{{header|Raku}}: simplifying first version and commenting the second one) |
(→{{header|Raku}}: clarify $width and $height) |
||
Line 11,402:
(formerly Perl 6)
{{Works with|rakudo|v2023.08-47-g695b9dc46}}
Using the [https://raku.land/zef:raku-community-modules/Color color module] to create a palette.
Line 11,411 ⟶ 11,410:
[[File:mandelbrot-raku-1.2.png|300px|thumb|right]]
<syntaxhighlight lang="perl6" line>constant
my $width
my $height = $width div 2 + 1;
say "P3";▼
say "$width $height";
say "255";▼
sub cut(Range $r, UInt $n where $n > 1 --> Seq) {
Line 11,418 ⟶ 11,421:
}
my @re = cut(-2 .. 1/2, $
my @im = cut( 0 .. 5/4, $
sub mandelbrot(Complex $z is copy, Complex $c --> Int) {
for 1 ..
$z = $z*$z + $c;
return $_ if $z.abs > 2;
Line 11,428 ⟶ 11,431:
return 0;
}
▲say "P3";
▲say "255";
hyper for @im.reverse X+ @re {
use Color;
my $i = (255 * sqrt(mandelbrot(0i, $_) / (
(state @)[$i] //= Color.new(hsv => $i xx 3).rgb
}.rotor(
</syntaxhighlight>
|