Created
May 13, 2014 12:41
-
-
Save davetang/7111e6edb56d1ae9bf05 to your computer and use it in GitHub Desktop.
The Mandelbrot set is a mathematical set of points whose boundary is a distinctive and easily recognizable two-dimensional fractal shape
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use warnings; | |
use strict; | |
my $BAILOUT=16; | |
my $MAX_ITERATIONS=1000; | |
my $begin = time(); | |
sub mandelbrot { | |
my ($x,$y) = @_; | |
my $cr = $y - 0.5; | |
my $ci = $x; | |
my $zi = my $zr = my $i = 0; | |
while (1){ | |
$i += 1; | |
my $temp = $zr * $zi; | |
my $zr2 = $zr * $zr; | |
my $zi2 = $zi * $zi; | |
$zr = $zr2 - $zi2 + $cr; | |
$zi = $temp + $temp + $ci; | |
if ($zi2 + $zr2 > $BAILOUT){ | |
return $i; | |
} | |
if ($i > $MAX_ITERATIONS){ | |
return 0; | |
} | |
} | |
} | |
for (my $y = -39; $y < 39; $y++){ | |
print("\n"); | |
for (my $x = -39; $x < 39; $x++){ | |
my $i = mandelbrot($x/40, $y/40); | |
if ($i == 0){ | |
print("*"); | |
} | |
else{ | |
print(" "); | |
} | |
} | |
} | |
print("\n"); | |
my $end = time() - $begin; | |
printf ("Perl Elapsed %.3f\n",$end); | |
exit(0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment