Source code:
//+------------------------+
//| pie3dfun.PHP//Public functions|
//+------------------------+
define("ANGLE_STEP", 5); //Define the angle step when drawing an elliptical arc
function draw_getdarkcolor($img,$clr) //Find the dark color corresponding to $clr
{
$rgb = imagecolorsforindex($img,$clr);
return array($rgb["red"]/2,$rgb["green"] /2,$rgb["blue"]/2);
}
function draw_getexy($a, $b, $d) //Find the ellipse corresponding to angle $d Point coordinates
{
$d = deg2rad($d);
return array(round($a*Cos($d)), round($b* Sin($d)));
}
function draw_arc($img,$ox,$oy,$a,$b,$sd,$ed,$clr) // Elliptic arc function
{
$n = ceil(($ed-$sd)/ANGLE_STEP);
$d = $sd;
list($x0,$y0) = draw_getexy($a,$b,$d);
for($i=0; $i<$n; $i++)
{
$d = ($d+ANGLE_STEP)>$ed?$ed:($d+ANGLE_STEP);
list($x, $y) = draw_getexy($a, $b, $d);
imageline($img, $x0+$ox, $y0+$oy, $x+$ox, $y+$oy, $clr);
$x0 = $x;
$y0 = $y;
}
}
function draw_sector($img, $ox, $oy, $a , $b, $sd, $ed, $clr) //Draw a fan
{
$n = ceil(($ed-$sd)/ANGLE_STEP);
$d = $sd;
list($x0,$y0) = draw_getexy($a, $b, $d);
imageline($img, $x0+$ox , $y0+$oy, $ox, $oy, $clr);
for($i=0; $i<$n; $i++)
{
$d = ($d+ANGLE_STEP)>$ed?$ed:($d+ANGLE_STEP);
list($x, $y) = draw_getexy($a, $b, $d );
imageline($img, $x0+$ox, $y0+$oy, $x+$ox, $y+$oy, $clr);
$x0 = $x;
$y0 = $y;
}
imageline($img, $x0+$ox, $y0+$oy, $ox, $oy, $clr);
list($x, $y) = draw_getexy($a/2, $b/2, ($d+$sd)/2);
imagefill($img, $x+$ ox, $y+$oy, $clr);
}