Source code for the Pointless PHP Mandelbrot Generator.
$width = 100.0;
$height = 40.0;
if (is_NULL($_GET["t"])) {
$type = 2;
} else {
$type=$_GET["t"];
if ($type < 2 || $type > 4 ) $type = 2;
}
if (is_NULL($_GET["x"]) ||
is_NULL($_GET["y"]) ||
is_NULL($_GET["r"]) ||
is_NULL($_GET["i"])) {
if ($type == 2) {
$range = 2.5;
$xCenter = -0.5;
$yCenter = 0.0;
$iMax = 64;
}
if ($type == 3) {
$range = 2.7;
$xCenter = 0.0;
$yCenter = 0.0;
$iMax = 64;
}
if ($type == 4) {
$range = 2.2;
$xCenter = -0.25;
$yCenter = 0.0;
$iMax = 64;
}
} else {
$xCenter = $_GET["x"];
$yCenter = $_GET["y"];
$range = $_GET["r"];
$iMax = $_GET["i"];
}
$newRange = $range*0.6;
$newIMax = $iMax*1.4;
function inSet($cx, $cy, $maxiter) {
$a = 0.0;
$b = 0.0;
$a2 = 0.0;
$b2 = 0.0;
$i = 0;
do {
$tmp = $a2 - $b2 + $cx;
$b = 2.0*$a*$b + $cy;
$a = $tmp;
$a2 = $a*$a;
$b2 = $b*$b;
$i++;
} while($a2 + $b2 < 4.0 && $i < $maxiter);
if ($a2 + $b2 < 4.0) return TRUE;
return FALSE;
}
function inSetZ3($cx, $cy, $maxiter) {
$a = 0.0;
$b = 0.0;
$a2 = 0.0;
$b2 = 0.0;
$i = 0;
do {
$tmp = $a*($a2 - 3*$b2) + $cx;
$b = $b*(3*$a2 - $b2) + $cy;
$a = $tmp;
$a2 = $a*$a;
$b2 = $b*$b;
$i++;
} while($a2 + $b2 < 4.0 && $i < $maxiter);
if ($a2 + $b2 < 4.0) return TRUE;
return FALSE;
}
function inSetZ4($cx, $cy, $maxiter) {
$a = 0.0;
$b = 0.0;
$a2 = 0.0;
$b2 = 0.0;
$i = 0;
do {
$tmp = $a2*($a2 - 6*$b2) + $b2*$b2 + $cx;
$b = 4*$a*$b*($a2 - $b2) + $cy;
$a = $tmp;
$a2 = $a*$a;
$b2 = $b*$b;
$i++;
} while($a2 + $b2 < 4.0 && $i < $maxiter);
if ($a2 + $b2 < 4.0) return TRUE;
return FALSE;
}
$self=$_SERVER["PHP_SELF"];
$j=0;
while ($j < $height) {
$y = $yCenter + $range*($j - $height/2.0)/$height;
$i = 0;
while ($i < $width) {
$x = $xCenter + $range*($i - $width/2.0)/$width;
print("<a href=\"$self?");
print("x=$x&y=$y&r=$newRange&i=$newIMax&t=$type\">");
if (($type == 2 && inSet($x, $y, $iMax)) ||
($type == 3 && inSetZ3($x, $y, $iMax)) ||
($type == 4 && inSetZ4($x, $y, $iMax))) {
print("*");
} else {
print("-");
}
print("</a>");
$i++;
}
print("<br>");
$j++;
}
print("<br><br>");
print("Reset: <a href=\"ppmg.php?t=2\">z = z^2 + c</a>");
print(" <a href=\"ppmg.php?t=3\">z = z^3 + c</a>");
print(" <a href=\"ppmg.php?t=4\">z = z^4 + c</a>");