Skip to content

Commit cfaf599

Browse files
committed
Adicona escolha de tamanho do board pixel
1 parent 9368d42 commit cfaf599

File tree

3 files changed

+174
-0
lines changed

3 files changed

+174
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//SELEÇÃO HTML
2+
const imputBoardSize = document.getElementById('board-size');
3+
let pixelBoard = document.getElementById('pixel-board');
4+
const buttonGenerateBoard = document.getElementById('generate-board');
5+
6+
7+
//MUNDA QUANTIDADE DE PIXEL PARA PINTAR.
8+
function sizeBoard() {
9+
let imputValue = imputBoardSize.value;
10+
if (imputValue < 5) {
11+
imputValue = 5;
12+
} else if (imputValue > 50) {
13+
imputValue = 50;
14+
}
15+
for (let c = 0; c < imputValue; c += 1) {
16+
let newLine = document.createElement('div');
17+
newLine.id = 'board' + c;
18+
newLine.className = 'newLine';
19+
pixelBoard.appendChild(newLine);
20+
for (let d = 0; d < imputValue; d += 1) {
21+
let newColun = document.createElement('div');
22+
newColun.className = 'pixel color-white size border horizontal';
23+
let aux = document.getElementById('board' + c);
24+
aux.appendChild(newColun);
25+
}
26+
}
27+
28+
}
29+
// console.log(pixelBoard); //TESTAR TAMANHO.
30+
31+
buttonGenerateBoard.addEventListener('click', function () {
32+
if (imputBoardSize.value === '') {
33+
alert('Tamanho inválido!');
34+
} else {
35+
pixelBoard.innerHTML = '';
36+
sizeBoard();
37+
}
38+
})
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
//SELEÇÃO DO HTML.
2+
let selected = document.getElementsByClassName('selected')[0].classList[1];
3+
let colorStore = 'background-color: rgb(0, 0, 0)';
4+
5+
const title = document.getElementById('title');
6+
7+
const colorPalette = document.getElementById('color-palette');
8+
let colorRed = document.getElementsByClassName('color-red');
9+
let colorBlue = document.getElementsByClassName('color-blue');
10+
let colorGreen = document.getElementsByClassName('color-green');
11+
let color = document.getElementsByClassName('color');
12+
13+
const clearBoard = document.getElementById('clear-board');
14+
const imputBoardSize = document.getElementById('board-size');
15+
const buttonGenerateBoard = document.getElementById('generate-board');
16+
17+
18+
let pixelBoard = document.getElementById('pixel-board');
19+
let line = document.getElementsByClassName('line');
20+
const board1 = document.getElementsByClassName('board1');
21+
const board2 = document.getElementsByClassName('board2');
22+
const board3 = document.getElementsByClassName('board3');
23+
const board4 = document.getElementsByClassName('board4');
24+
const board5 = document.getElementsByClassName('board5');
25+
let pixel = document.getElementsByClassName('pixel');
26+
27+
//INICIA COM BACKGROUND-COLOR: BLACK;
28+
function colorize(paint) {
29+
let aux = paint.classList[1];
30+
paint.classList.replace(aux, selected);
31+
}
32+
33+
pixelBoard.addEventListener('click', function (event) {
34+
colorize(event.target);
35+
// console.log(event.target); //TESTAR SELEÇÃO
36+
})
37+
38+
//GERA CORES ALETORIAS NA PALETA DE CORES.
39+
function generateColor() {
40+
41+
const letters = '0123456789ABCDEF';
42+
let color = '#';
43+
44+
for (let e = 0; e < 6; e += 1) {
45+
color += letters[Math.floor(Math.random() * 16)];
46+
}
47+
48+
return color;
49+
50+
}
51+
52+
for (let f = 1; f < color.length; f += 1){
53+
let capatAux = 'background-color: ' + generateColor();
54+
color[f].setAttribute('style', capatAux);
55+
}
56+
57+
58+
//SELECIONA COR NA PALETA.
59+
function colorSelect(selection) {
60+
for (let i = 0; i < color.length; i += 1) {
61+
color[i].classList.remove('selected');
62+
if (selection === color[i]) {
63+
selection.classList.toggle('selected');
64+
selected = document.getElementsByClassName('selected')[0].classList[1];
65+
}
66+
}
67+
}
68+
69+
colorPalette.addEventListener('click', function (event) {
70+
let teste = window.getComputedStyle(event.target);
71+
let teste2 = teste.getPropertyValue('background-color');
72+
colorStore = teste2;
73+
colorSelect(event.target);
74+
console.log(colorStore);
75+
// console.log(color); //TESTAR SELEÇÃO
76+
// console.log(selected); //TESTAR SELEÇÃO
77+
})
78+
79+
//COLORE PIXEL.
80+
function colorize2(paint) {
81+
// let aux = window.getComputedStyle(paint);
82+
// let aux2 = aux.getPropertyValue('background-color');
83+
// paint.setAttribute('style', 'background-color' + aux2)
84+
// let aux = paint.classList[1];
85+
paint.setAttribute('style', 'background-color: ' + colorStore);
86+
}
87+
88+
pixelBoard.addEventListener('click', function (event) {
89+
colorize2(event.target);
90+
// console.log(event.target); //TESTAR SELEÇÃO
91+
})
92+
93+
//LIMPA PIXELS.
94+
clearBoard.addEventListener('click', function () {
95+
location.reload();
96+
});
97+
98+
//MUNDA QUANTIDADE DE PIXEL PARA PINTAR.
99+
function sizeBoard() {
100+
let imputValue = imputBoardSize.value;
101+
if (imputValue < 5) {
102+
imputValue = 5;
103+
} else if (imputValue > 50) {
104+
imputValue = 50;
105+
}
106+
for (let c = 0; c < imputValue; c += 1) {
107+
let newLine = document.createElement('div');
108+
newLine.id = 'board' + c;
109+
newLine.className = 'newLine';
110+
pixelBoard.appendChild(newLine);
111+
for (let d = 0; d < imputValue; d += 1) {
112+
let newColun = document.createElement('div');
113+
newColun.className = 'pixel color-white size border horizontal';
114+
let aux = document.getElementById('board' + c);
115+
aux.appendChild(newColun);
116+
}
117+
}
118+
119+
}
120+
// console.log(pixelBoard); //TESTAR TAMANHO.
121+
122+
123+
buttonGenerateBoard.addEventListener('click', function () {
124+
if (imputBoardSize.value === '') {
125+
alert('Board inválido!');
126+
} else {
127+
pixelBoard.innerHTML = '';
128+
sizeBoard();
129+
}
130+
})
131+

trybe-projetos/pixels-art/style.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,14 @@
5353

5454
.border {
5555
border: solid 1px;
56+
margin: -2px;
5657
}
5758

5859
.size {
5960
width: 40px;
6061
height: 40px;
6162
}
63+
64+
.space {
65+
margin: 0;
66+
}

0 commit comments

Comments
 (0)