Fabrizio Zellini * */ $nomi = Array( 3=>"triangolo", 4=>"quadrato", 5=>"pentagono", 6=>"esagono", 7=>"ettagono", 8=>"ottagono", 9=>"ennagono", 10=>"decagono", 11=>"endecagono", 12=>"dodecagono" ); function drawTextAligned ($im,$sr,$xc,$y,$font,$font_size,$fontcolor){ $dimensions = imageftbbox ( $font_size , 0 , $font , $sr); $spacepx = $dimensions[4] - $dimensions[0]; $x = $xc - $spacepx/2; imagettftext($im, $font_size, 0, $x, $y, $fontcolor, $font, $sr); } // Set the content-type // Set the environment variable for GD putenv('GDFONTPATH=' . realpath('.')); // prelevo qs //poly?lati=7 $lati = 3; if (array_key_exists ("lati",$_GET)) { $lati = $_GET["lati"]; } if ($lati<3 || $lati>50) {header("HTTP/1.0 404 Not Found");die;} $size=80; if (array_key_exists ("size",$_GET)) { $size = $_GET["size"]; } if ($size<80 || $size>1024) { {header("HTTP/1.0 404 Not Found");die;} } $px = 10; // Name the font to be used (note the lack of the .ttf extension) $font = 'arialn'; // Get the image size //$size = imagettfbbox($px,0,$font,$sr); // Create the image $im = imagecreate($size,$size); $black = imagecolorallocate($im, 0, 0, 0); imagecolortransparent($im, $black); $alpha = imagecolorallocatealpha($im, 255, 255, 0, 90); //$alpha = imagecolorallocate($im, 0, 255, 0); $color = imagecolorallocatealpha($im, 0, 0, 0 , 0); $nfisso = tan(($lati-2)/(2*$lati)*M_PI)/2; $f_area = ($lati * $nfisso) / 2; $x1=-1;$y1=-1; $stepangle = 2*M_PI/$lati; $lato=0; $angle=0; // non mi chiedete perchè ! if ($lati%2==0) { if (($lati/2)%2==0) { $angle = M_PI/$lati; } } else { if ((($lati-1)/2)%2==0) { $angle = M_PI/($lati*2); } else { $angle = M_PI/($lati*2)+M_PI; } } // cerchio inscritto e circoscritto $f = sqrt(pow(sin($stepangle),2)+pow(1-cos($stepangle),2))*$nfisso*$size; $color_raggio = imagecolorallocatealpha($im, 0, 255, 0 , 0); $a_angle = (M_PI/4)*3; $colorcircle = imagecolorallocatealpha($im, 95, 24, 237 , 90); imagearc ( $im , $size/2 , $size/2 , $size , $size , 0, 360 , $colorcircle ); imagearc ( $im , $size/2 , $size/2 , $f , $f , 0, 360 , $colorcircle ); for ($lato=0;$lato<=$lati;$lato++) { $dy = (sin ($angle)*$size/2); $dx = (cos ($angle)*$size/2); $x2 = $size/2 + $dx; $y2 = $size/2 - $dy; if ($lato!=$lati) imageline ( $im , $size/2 , $size/2 , $x2 , $y2 , $color_raggio ); if ($x1!=-1) { imageline ( $im , $x1 , $y1 , $x2 , $y2 , $color ); } $x1 = $x2; $y1 = $y2; $angle0 = $angle; $angle+=$stepangle; } // disegno l'apotema in basso $colorapo = imagecolorallocatealpha($im, 255, 0, 0 , 0); imageline ( $im , $size/2 , $size/2 , $size/2 , $size/2+$f/2 , $colorapo ); // informazioni if ($size>=400) { $sr=$lati." lati"; $font_size = $size/10; $fontcolor = imagecolorallocatealpha($im, 255, 0, 0 , 80); $y = $size/4; drawTextAligned ($im,$sr,$size/2,$y,$font,$font_size,-$fontcolor); $font_size=(int)$font_size/2; if (array_key_exists ($lati,$nomi)){ $sr = $nomi[$lati]; $y+=$font_size; drawTextAligned ($im,$sr,$size/2,$y,$font,$font_size,-$fontcolor); } $y+=$font_size*2; $sr = sprintf ("numero fisso %.3f",$nfisso); drawTextAligned ($im,$sr,$size/2,$y,$font,$font_size,-$fontcolor); $y+=$font_size*2; $sr = sprintf ("Area = l² x %.3f",$f_area); drawTextAligned ($im,$sr,$size/2,$y,$font,$font_size,-$fontcolor); // apotema $sr = "apotema"; $y = $size/2 + ($f/3); imagettftext($im, 15, 90, $size/2, $y, -$colorapo, $font, $sr); } header("Content-type: image/png"); imagepng($im); imagedestroy($im); ?>