Desafío Poligonator
#3 Solución de infinit
Ver código
|
Ver comentarios (7)
|
Descargar código
Fecha: 17 septiembre 2005
Tamaño: 6782 caracteres
Comentarios: 7
Solución online:
http://www.100foros.com/poligonator.php
Valoración









7.29
(7 votos)
"Lo tenia hecho desde hace tiempo, pero lo mando ahora xD.
Podeis ver como queda aquí: http://www.100foros.com/poligonator.php"
Valora esta solución
<?php
if (!empty($_GET['vertices'])) {
define('width', 200);
define('height', 200);
define('radio', 50);
$im = ImageCreate(width, height);
$cx = ImagesX($im) / 2;
$cy = ImagesY($im) / 2;
$blanco = ImageColorAllocate($im, 255, 255, 255);
$negro = ImageColorAllocate($im, 0, 0, 0);
$nvertices = $_GET['vertices'];
$angulo = (2 * M_PI) / $nvertices;
for ($i = 0; $i <= $nvertices; $i++) {
$rad = $angulo * $i;
list($x, $y) = array(cos($rad) * radio + $cx, sin($rad) * radio + $cy);
if ($i != 0) ImageLine($im, $xt, $yt, $x, $y, $negro);
list($xt, $yt) = array($x, $y);
}
Header('Content-type: Image/png');
ImagePng($im);
} else {
?>
<form method="get" action="<?php echo $_SERVER['php_self']; ?>">
<input type="text" size="3" name="vertices" />
<input type="submit" value="Crear polígono">
</form>
<?php
}
?>