How to resolve the algorithm Mandelbrot set step by step in the Raku programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Mandelbrot set step by step in the Raku programming language
Table of Contents
Problem Statement
Generate and draw the Mandelbrot set.
Note that there are many algorithms to draw Mandelbrot set and there are many functions which generate it .
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Mandelbrot set step by step in the Raku programming language
Source code in the raku programming language
constant MAX-ITERATIONS = 64;
my $width = +(@*ARGS[0] // 800);
my $height = $width + $width %% 2;
say "P2";
say "$width $height";
say MAX-ITERATIONS;
sub cut(Range $r, UInt $n where $n > 1 --> Seq) {
$r.min, * + ($r.max - $r.min) / ($n - 1) ... $r.max
}
my @re = cut(-2 .. 1/2, $width);
my @im = cut( 0 .. 5/4, 1 + ($height div 2)) X* 1i;
sub mandelbrot(Complex $z is copy, Complex $c --> Int) {
for 1 .. MAX-ITERATIONS {
$z = $z*$z + $c;
return $_ if $z.abs > 2;
}
return 0;
}
my @lines = hyper for @im X+ @re {
mandelbrot(0i, $_);
}.rotor($width);
.put for @lines[1..*].reverse;
.put for @lines;
You may also check:How to resolve the algorithm Calkin-Wilf sequence step by step in the Prolog programming language
You may also check:How to resolve the algorithm Evaluate binomial coefficients step by step in the 11l programming language
You may also check:How to resolve the algorithm String length step by step in the Robotic programming language
You may also check:How to resolve the algorithm Abbreviations, automatic step by step in the AWK programming language
You may also check:How to resolve the algorithm Ethiopian multiplication step by step in the JavaScript programming language