Dibujar con canvas
Publicado por ayuda (2 intervenciones) el 01/10/2019 19:51:15
hola! he tratado de desarrollar este codgo que e spara dibujar con canvas pero por ulgun motivo no me corre,podrian decirme que esta mal?muchas gracias
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
var texto = document.getElementById("texto_lineas");
var boton = document.getElementById("botoncito");
var borrar = document.getElementById("borrar");
boton.addEventListener("click", dibujoPorClick );
boton.addEventListener("click", borrarCanvas );
var d = document.getElementById("dibujito");
var ancho = d.width;
var lienzo = d.getContext("2d");
function dibujarLineas(color, xinicial, yinicial, xfinal, yfinal)
{
lienzo.beginPath();
lienzo.strokeStyle = color;
lienzo.moveTo(xinicial, yinicial);
lienzo.lineTo(xfinal, yfinal);
lienzo.stroke();
lienzo.closePath();
}
function dibujoPorClick()
{
var lineas = parseInt(texto.value);
var l = 0;
var xi, yi, xf, yf;
var espacio = ancho / lineas;
for(l = 0; l < lineas; l++)
{
yi = espacio * l;
xf = espacio * (l + 1);
dibujarLineas("pink", 0, yi, xf, 300);
dibujarLineas("green", xf, 2, 299, yi);
dibujarLineas("yellow", 0, 300 - xi , xi, 0);
dibujarLineas("blue", 280, 248, xi, yi, 2);
dibujarLineas("purple", ancho - 2, 5, ancho -3, ancho - 1);
l = l + 1;
}
}
function borrarCanvas()
{
lienzo.clearRect(0, 0, 300, 300)
}
}
Valora esta pregunta


0