Mandelbrot set: Difference between revisions

→‎{{header|Raku}}: keeping things simple : producing a bitmap
(→‎{{header|Raku}}: fuse last two lines)
(→‎{{header|Raku}}: keeping things simple : producing a bitmap)
Line 11,464:
=={{header|Raku}}==
(formerly Perl 6)
{{Works with|rakudo|v20232023.08-473-g695b9dc46g2f8234c22}}
 
Using the [https://docs.raku.landorg/zef:rakulanguage/statement-community-modules/Colorprefixes#hyper,_race colorhyper modulestatement prefix] to create afor paletteconcurrency.
Produces a bitmap in [[Write ppm file|Portable Pixel Map]] format to standard output.
Trying to use concurrency as much as possible.
Produces a [[Write ppm file|Portable Pixel Map]] to standard output
Redirect into a file to save it.
Converted to a JPEG file for display here.
 
<!--[[File:mandelbrot-raku.jpg|300px|thumb|right]]-->
<syntaxhighlight lang="raku">constant MAX-ITERATIONS = 1000;
my $width = +(@*ARGS[0] // 800);
my $height = $width + $width %% 2;
say "P3P1";
say "$width $height";
say "255";
 
sub cut(Range $r, UInt $n where $n > 1 --> Seq) {
Line 11,490 ⟶ 11,487:
for 1 .. MAX-ITERATIONS {
$z = $z*$z + $c;
return $_0 if $z.abs > 2;
}
return 01;
}
my @lines = hyper for @im X+ @re {
mandelbrot(0i, $_);
use Color;
my $i = (255 * sqrt(mandelbrot(0i, $_) / (MAX-ITERATIONS + 1))).Int;
(state @)[$i] //= Color.new(hsv => $i xx 3).rgb
}.rotor($width);
 
1,934

edits