$points = star(8,200,50);
$points = translatePolygon($points,200,200);
$image = imagecreatetruecolor(400,400);
$white = imagecolorallocate($image,255,255,255);
imagefill($image,0,0,$white);
$red = imagecolorallocate($image,255,0,0);
imagefilledpolygon($image,$points,(count($points)/2),$red);
header("Content-type: image/png");
imagepng($image);
imagedestroy($image);
function star($number_of_points,$outer_radius=100,$inner_radius=40) {
$p = array();
$degrees = 360/($number_of_points*2);
for ($i=0;$i<$number_of_points*2;$i++) {
$cos = cos(deg2rad($degrees*$i));
$sin = sin(deg2rad($degrees*$i));
$x = 0;
$y = ($i%2==0)?$outer_radius:$inner_radius;
$p[] = round($cos*($x) - $sin*($y));
$p[] = round($sin*($x) + $cos*($y));
}
return $p;
}
function translatePolygon($points,$x=0,$y=0) {
for($i=0;$i $points[$i] = $points[$i] + $x;
$points[$i+1] = $points[$i+1] + $y;
}
return $points;
}
?>