Skip to content

Commit

Permalink
mandelbrot-color.pl, README
Browse files Browse the repository at this point in the history
  • Loading branch information
moritz committed Dec 13, 2009
1 parent 7c182d3 commit 3067d00
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The Perl 6 sccripts mandelbrot.pl and mandelbrot-color.pl emit PBM and PMM
files to STDOUT, showing a small Mandelbrot fractal.
31 changes: 31 additions & 0 deletions mandelbrot-color.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use v6;

my $height = 35;
my $width = $height;
my $max_iterations = 50;

my $upper-right = -2 + (5/4)i;
my $lower-left = 1/2 - (5/4)i;

sub mandel(Complex $c) {
my $z = 0i;
for ^$max_iterations {
return $_ if ($z.abs > 2);
$z = $z * $z + $c;
}
return $max_iterations;
}

sub subdivide($low, $high, $count) {
(^$count).map({ $low + ($_ / ($count - 1)) * ($high - $low) });
}

say "P3";
say "$width $height";
say $max_iterations;

for subdivide($upper-right.re, $lower-left.re, $height) -> $re {
my @line = subdivide($re + ($upper-right.im)i, $re + 0i, ($width + 1) / 2).map({ mandel($_) });
my $middle = @line.pop;
(@line, $middle, @line.reverse).map({ $_ xx 3 }).join(' ').say;
}

0 comments on commit 3067d00

Please sign in to comment.