-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
55 lines (49 loc) · 1.34 KB
/
main.js
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
46
47
48
49
50
51
52
53
54
55
document.addEventListener("DOMContentLoaded", main);
function main() {
let pa = new PixelArt();
pa.dibujarTabla();
pa.dibujarCuadrado(0, 0);
let colors = document.getElementsByClassName("colors")[0].childNodes;
for (const key in colors) {
console.log(colors[key].nodeName);
if (colors[key].nodeName === "DIV") {
colors[key].onclick = function() {
pa.color = colors[key].id;
pa.dibujarCuadrado(pa.x, pa.y);
}
}
}
document.addEventListener("keydown", function(e)
{
switch (e.keyCode)
{
case 32:
pa.pintar();
break;
case 17:
pa.borrar();
break;
case 37:
pa.moverIzquierda();
break;
case 38:
pa.moverArriba();
break;
case 39:
pa.moverDerecha();
break;
case 40:
pa.moverAbajo();
break;
}
});
document.addEventListener("keyup", function(e)
{
switch (e.keyCode)
{
case 17:
pa.dibujarCuadrado(pa.x, pa.y, pa.color);
break;
}
});
}