> 16) & 0xFF, ($rgb >> 8) & 0xFF, $rgb & 0xFF); } for ($i=0; $i 2 ever, then the sequence will tend to infinity so we can exit the loop while ($iteration <= MAX_ITERATIONS && $x2+y2 <= 4) { // In order to get the next term in the sequence // we need to square the previous number and then add // the original complex number // // z(n+1) = z(n)^2+c $k = $z; // z is a complex number. When we square a complex number in the form x+yi: // New real component: x^2-y^2 // New imaginary component: 2*real*imaginary $z[0] = $x2 - $y2; $z[1] = 2 * $k[0] * $k[1]; // Add Complex Number $z[0] = $z[0] + $x; $z[1] = $z[1] + $y; $x2 = pow($z[0], 2); $y2 = pow($z[1], 2); ++$iteration; } if ($iteration == MAX_ITERATIONS) { imagesetpixel($image, $i, $j, $colors['inside']); } else { imagesetpixel($image, $i, $j, $colors[$iteration]); } } } $time_end = microtime_float(); header ("X-Exec-Time: ".($time_end - $time_start)); imagepng($image); ?>