Desafío Poligonator
#3 Solución de AaMP3rio
Ver código
|
Ver comentarios (8)
|
Descargar código
Fecha: 03 septiembre 2005
Tamaño: 6616 caracteres
Comentarios: 8
Solución online:
Lo siento, pero no está disponible
Valoración









9.25
(8 votos)
"Bueno, yo también me estreno aquí... jeje.
Un reto muy sencillo, pura matemática.
Había olvidado poner el formulario."
Valora esta solución
<?php
if (@isset($_GET['n'], $_GET['r'], $_GET['m'])) {
$n = $_GET['n'];
$r = $_GET['r'];
$m = $_GET['m'];
$w = $r * 2 + $m;
$img = imagecreate($w, $w);
imagecolorallocate($img, 255, 255, 255);
$b = imagecolorallocate($img, 0, 0, 0);
$w /= 2;
for ($i = 1; $i <= $n + 1; $i++) {
if (isset($x, $y)) {
$a = $w + ($r * sin(deg2rad($i * 360 / $n)));
$b = $w - ($r * cos(deg2rad($i * 360 / $n)));
imageline($img, $x, $y, $a, $b, $b);
}
$x = $w + ($r * sin(deg2rad($i * 360 / $n)));
$y = $w - ($r * cos(deg2rad($i * 360 / $n)));
}
header('Content-type: image/png');
imagepng($img);
exit;
}
?>
<html>
<head><title>Poligonator</title></head>
<body>
<form>
<pre>
<input type="text" size="5" name="n" value="5"> - Lados
<input type="text" size="5" name="r" value="50"> - Radio
<input type="text" size="5" name="m" value="100"> - Margin
</pre><input type="submit" value="poligonize">
</form>
</body></html>