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;
}
function boundary_fill($x, $y, $width, $height, $points, &$area)
{
if (($x < 0) || ($x >= $width)) return;
if (($y < 0) || ($y >= $height)) return;
$current = array_search(array($x,$y),$points);
echo "$x,$y ";
//array search pixel
if ($current === false) {
echo "false\n";
//raster.setPixel(fill, x, y);
$area[] = array($x,$y);
boundary_fill($x+1, $y, $width,$height, $points,$area);
boundary_fill($x, $y+1, $width,$height, $points,$area);
boundary_fill($x-1, $y, $width,$height, $points,$area);
boundary_fill($x, $y-1, $width,$height, $points,$area);
}else{
echo "true\n";
}
}
$im = imagecreatetruecolor(400, 400);
$points = circle_midpoint(10,100,50);
$color = imagecolorallocate($im, 255, 0, 0);
foreach ($points as $pixel){
imagesetpixel($im,$pixel[0],$pixel[1],$color);
}
boundary_fill(10,100,400,400,$points,$area);
foreach ($area as $pixel){
imagesetpixel($im,$pixel[0],$pixel[1],$color);
}
imagepng($im,'testing.png');
?>