Permalink
Browse files

Initial commit of code.

  • Loading branch information...
1 parent 9051ee7 commit 7c182d3ec90384859958a3740507567a68ff7ef6 @colomon committed Dec 13, 2009
Showing with 29 additions and 0 deletions.
  1. +29 −0 mandelbrot.pl
View
@@ -0,0 +1,29 @@
+use v6;
+
+my $height = 41;
+my $width = 41;
+
+my $upper-right = -2 + (5/4)i;
+my $lower-left = 1/2 - (5/4)i;
+
+sub mandel(Complex $c) {
+ my $z = 0i;
+ for ^50 {
+ return 0 if ($z.abs > 2);
+ $z = $z * $z + $c;
+ }
+ return 1;
+}
+
+sub subdivide($low, $high, $count) {
+ (^$count).map({ $low + ($_ / ($count - 1)) * ($high - $low) });
+}
+
+say "P1";
+say "$width $height";
+
+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).join(' ').say;
+}

0 comments on commit 7c182d3

Please sign in to comment.