|
CORAZÓN 1 |
MUJER |
PINGUINO |
CORAZÓN 2 |
En el siguiente script se puede probar las instrucciones para generar Arte Pixel:
Código fuente del generador de Arte Pixel en JavaScript:
<div>
<form style="background-color: lightgrey;" >
Ancho:<br> <input type = text id =ancho placeholder="Ancho" /> <br>
Instrucciones:<br> <textarea rows="30" cols="20" id="texto" placeholder="Instrucciones">
</textarea>
<p> <button onclick="armar()" type="button">Armar</button> </p>
<p> <button onclick="borrar()" type="button">Borrar</button> </p>
</form>
</div>
<div id ="tabla">
</div>
<script>
function armar()
{
var s,text,a,color,pasos,linea,i,ancho,anchoactual,j,canlineas,colorcelda;
s = document.getElementById("texto").value;
ancho = parseInt(document.getElementById("ancho").value);
a = s.split(/\n/);
text = "<table border = 1 cellpadding= 0 cellspacing = 0>";
i=0;
anchoactual = 0;
canlineas = a.length;
while (i < canlineas)
{
linea = a[i];
color = linea[0];
pasos = parseInt(linea.slice(1));
for (j=1;j<=pasos;j++)
{
if (anchoactual==0)
{
text = text + "<tr>";
}
colorcelda = " ";
if (color == "N" || color == "n" )
{
colorcelda = " bgcolor = black ";
}
else if (color == "A" || color == "a" )
{
colorcelda = " bgcolor = blue ";
}
else if (color == "J" || color == "j" )
{
colorcelda = " bgcolor = orange ";
}
else if (color == "M" || color == "m" )
{
colorcelda = " bgcolor = brown ";
}
else if (color == "V" || color == "v" )
{
colorcelda = " bgcolor = green ";
}
else if (color == "R" || color == "r" )
{
colorcelda = " bgcolor = red ";
}
else if (color == "G" || color == "g" )
{
colorcelda = " bgcolor = gray ";
}
else
{
colorcelda = " ";
}
text = text + "<td "+colorcelda+"> </td>";
anchoactual++;
if (anchoactual>=ancho)
{
text = text + "</tr>";
anchoactual=0;
}
}
i++;
}
text = text+"</table>";
document.getElementById("tabla").innerHTML = text;
}
function borrar()
{
var text;
text = "";
document.getElementById("tabla").innerHTML = text;
}
</script>
No hay comentarios.:
Publicar un comentario