function draw_axes() { global $im, $black, $gray; for ($x = -1.1; $x <= 1.1; $x += 0.2) { imagearc($im, transform_x($x), transform_y(y), 3, 3, 0, 360, $black); imagettftext($im, 10, 0, transform_x($x) - 10, transform_y(0) - 4, $black, FONT, $x); for ($y = 0; $y <= HEIGHT; $y += 30) { imageline($im, transform_x($x), $y, transform_x($x), $y + 10, $gray); } imagearc($im, transform_x($x), transform_y(f($x)), 3, 3, 0, 360, $black); for ($xprime = 0; $xprime <= transform_x($x); $xprime += 30) { imageline($im, $xprime, transform_y(f($x)), $xprime + 10, transform_y(f($x)), $gray); } imagettftext($im, 10, 0, transform_x($x) + 4, transform_y(f($x)), $black, FONT, round(f($x), 2)); } // x axis imageline($im, 0, HEIGHT / 2, WIDTH, HEIGHT / 2, $black); // y axis imageline($im, WIDTH / 2, 0, WIDTH / 2, HEIGHT, $black); // box imageline($im, 0, 0, WIDTH, 0, $black); imageline($im, 0, 0, 0, HEIGHT, $black); imageline($im, 0, HEIGHT - 1, WIDTH - 1, HEIGHT - 1, $black); imageline($im, WIDTH - 1, 0, WIDTH - 1, HEIGHT - 1, $black); }
{ return $x[0] * $x[0] + $x[1] + $x[1]; } function Mandelbrot($x, $y) { $z = 0; $c = array($x, $y); for ($i = 0; $i < N; ++$i) { $z = add(square($z), $c); if (value($z) > M) { return $i; } } return true; } $im = imagecreatetruecolor(WIDTH, HEIGHT); $white = imagecolorallocate($im, 255, 255, 255); $color = array(); for ($i = 0; $i < N; ++$i) { $clr = $i / N; $color[$i] = imagecolorallocate($im, 200 * $clr, 255 * $clr, 100 + $clr * 155); } imagefill($im, 0, 0, $white); for ($x = MIN_X; $x <= MAX_X; $x += RESOLUTION_X) { for ($y = MIN_Y; $y <= MAX_Y; $y += RESOLUTION_Y) { $i = Mandelbrot($x, $y); imagesetpixel($im, transform_x($x), transform_y($y), $color[$i]); } } header("Content-type: image/png"); imagepng($im);