Jump to content

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 MAX_ITERATIONSMAX-ITERATIONS = 1000;
my $width = my $height = +(@*ARGS[0] // 800);
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, $heightwidth);
my @im = cut( 0 .. 5/4, $width div 2 + 1height) X* 1i;
sub mandelbrot(Complex $z is copy, Complex $c --> Int) {
for 1 .. MAX_ITERATIONSMAX-ITERATIONS {
$z = $z*$z + $c;
return $_ if $z.abs > 2;
Line 11,428 ⟶ 11,431:
return 0;
}
say "P3";
say "{+@re} {+@im}";
say "255";
hyper for @im.reverse X+ @re {
use Color;
my $i = (255 * sqrt(mandelbrot(0i, $_) / (MAX_ITERATIONSMAX-ITERATIONS + 1))).Int;
(state @)[$i] //= Color.new(hsv => $i xx 3).rgb
}.rotor(+@im$width).map(&put);
</syntaxhighlight>
 
1,934

edits

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