Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
@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