<?php
$scale=4;
$Cols=130; $Lines=100;
$MaxIter=16;
$MinRe=-2.0; $MaxRe=1.0;
$MinIm=-1.0; $MaxIm=1.0;
$img = ImageCreate($Cols*$scale,$Lines*$scale);
for($n=0; $n<$MaxIter; $n++)
{
$pitch = (int)($n*256/$MaxIter);
$c[$n] = ImageColorAllocate($img, $pitch,$pitch,$pitch);
}
$y=0;
for($Im=$MinIm;$Im<=$MaxIm;$Im+=($MaxIm-$MinIm)/$Lines)
{
$x=0;
for($Re=$MinRe;$Re<=$MaxRe;$Re+=($MaxRe-$MinRe)/$Cols)
{
$zr=$Re; $zi=$Im;
for($n=0;$n<$MaxIter;$n++)
{
$a=$zr*$zr; $b=$zi*$zi;
if($a+$b>4.0) { break; }
$zi=2*$zr*$zi+$Im; $zr=$a-$b+$Re;
}
ImageFilledRectangle($img, $x*$scale, $y*$scale, ($x+1)*$scale-1, ($y+1)*$scale-1, $c[$n]);
++$x;
}
++$y;
}
header('Content-type: image/png');
header('Connection: close');
ImagePng($img);