function draw_mandelbrot ($width
{
$widthround$width);
$heightround$width*2/3.5);
// create image
$image = image_create_alpha$width, $height);
$max_iteration = 100;
// color pallet
$colorsarray();
for ($i=0;$i$max_iteration$i++) {
$shade = 60+round$i$max_iteration*195);
$colors$i] = imagecolorallocate$image, $shade, $shade, $shade);
}
// the "inside" color
$colors$max_iteration] = imagecolorallocate$image, 0, 0, 0);
// loop through all the pixels
for ($h = 0; $h < $height; $h++) {
for ($w = 0; $w < $width; $w++) {
// normalize the location of the pixel
$x0 = (3.5 * $w / $width)-2.5; // between -2.5 and 1
$y0 = (2 * $h / $height)-1; // between -1 and 1
$x = 0;
$y = 0;
$iteration = 0;
// the calculation
while ( ($x$x + $y$y <= (2*2)) && ($iteration < $max_iteration) ) {
$xtemp = $x$x - $y$y + $x0
$y = 2*$x$y + $y0
$x = $xtemp
$iteration = $iteration + 1;
}
// set color
imagesetpixel$image, $w, $h, $colors$iteration]);
}
}
return $image
}