Descripción: Con este extra se pueden generar sudokus.
A continuación mostramos los apuntes asociados a este extra:
// descripción para la sindicación:
/*
[rss]Con este extra se pueden generar sudokus.[/rss]
*/
if (isset($_GET["ancho"]))
$ancho = (int) $_GET["ancho"];
else
$ancho = 30;
if (isset($_GET["inicio"]))
$inicio = str_split($_GET["inicio"]);
else
$inicio = array();
$ns = str_split("123456789");
header("Content-type: image/svg+xml");
$anchura = $ancho * 9 + 21;
$anchon = $ancho + 2;
$pt = $ancho / 2.7;
$f = $ancho / 1.5;
$svg =<<< svg
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="{$anchura}px" height="{$anchura}px" preserveAspectRatio="none" viewBox="0 0 $anchura $anchura">
<rect x="0" y="0" width="$anchura" height="$anchura" stroke="black" fill="black"/>
svg;
unset($body);
unset($css);
echo $svg;
for ($i = 0; $i < 9; $i++) {
$incX = ($i / 3) + 1;
for ($j = 0; $j < 9; $j++) {
$incY = ($j / 3) + 1;
$x = $j * $anchon + $incY;
$y = $i * $anchon + $incX;
$num = ((int) ($i / 3) + (int) ($j / 3));
$fill = ($num % 2) ? "#abcabc": "white";
echo "<rect x='$x' y='$y' id='casilla_{$i}_{$j}' width='$ancho' height='$ancho' fill='$fill' stroke='black'/>";
if (count($inicio) > 0) {
$n = array_shift($inicio);
if (in_array($n, $ns)) {
$xx = $x + $pt;
$yy = $y + $pt + $ancho / 3;
echo "<text x='$xx' y='$yy' stroke='blue' font-size='$f'>$n</text>";
}
}
}
}
echo "</svg>";
Este código ha sido leído en 115 ocasiones.
Esta extra aún no tiene comentarios.
Valoración de esta página: (extra.sudoku)
Listados: imágenes, categorías, etiquetas, extras | Anuarios: 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 | Otros enlaces: buscador