rendered paste body<?php
function circle_points($cx, $cy, $x, $y)
{
if ($x == 0) {
$points[] = array($cx, $cy + $y);
$points[] = array($cx, $cy - $y);
$points[] = array($cx + $y, $cy);
$points[] = array($cx - $y, $cy);
} else
if ($x == $y) {
$points[] = array( $cx + $x, $cy + $y);
$points[] = array( $cx - $x, $cy + $y);
$points[] = array( $cx + $x, $cy - $y);
$points[] = array( $cx - $x, $cy - $y);
} else
if ($x < $y) {
$points[] = array( $cx + $x, $cy + $y);
$points[] = array( $cx - $x, $cy + $y);
$points[] = array( $cx + $x, $cy - $y);
$points[] = array( $cx - $x, $cy - $y);
$points[] = array( $cx + $y, $cy + $x);
$points[] = array( $cx - $y, $cy + $x);
$points[] = array( $cx + $y, $cy - $x);
$points[] = array( $cx - $y, $cy - $x);
}
return $points;
}
function circle_midpoint($xCenter, $yCenter, $radius)
{
$x = 0;
$y = $radius;
$p = (5 - $radius*4)/4;
$points = circle_points($xCenter, $yCenter, $x, $y);
while ($x < $y) {
$x++;
if ($p < 0) {
$p += 2*$x+1;
} else {
$y--;
$p += 2*($x-$y)+1;
}
if (is_array($points2 = circle_points($xCenter, $yCenter, $x, $y))) {
$points = array_merge($points,$points2);
}
}
return $points;
}
$im = imagecreatetruecolor(400, 400);
$points = circle_midpoint(100,100,50);
$color = imagecolorallocate($im, 255, 0, 0);
foreach ($points as $pixel){
imagesetpixel($im,$pixel[0],$pixel[1],$color);
}
imagepng($im,'testing.png');
?>