Skip to content

Instantly share code, notes, and snippets.

@JJ
Forked from windytan/mandelbrot.pl
Created October 27, 2015 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JJ/3cb9c9f497ad3c83d878 to your computer and use it in GitHub Desktop.
Save JJ/3cb9c9f497ad3c83d878 to your computer and use it in GitHub Desktop.
@size = (1920, 1080);
@center = (-.743653135, .131826563);
$zoom = .000014628;
$max_it = 700;
$oversample = 2;
$_ *= $oversample for (@size);
open $fh, "|-", "convert -size ".join("x",@size)." -depth 8 gray:- ".
"-resize ".(100/$oversample)."% mandel.png";
for $py (1 .. $size[1]) {
$y0 = $center[1] + ($py/$size[0] - .5) * $zoom;
for $px (1 .. $size[0]) {
$x0 = $center[0] + ($px/$size[0] - .5) * $zoom;
$x = $y = $it = 0;
while ($x*$x + $y*$y < 2*2 && $it++ < $max_it) {
$xt = $x*$x - $y*$y + $x0;
$y = 2*$x*$y + $y0;
$x = $xt;
}
print $fh pack("C",$it >= $max_it ? 0 : 127*(1+sin(3.1416/192 * $it)));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment