-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
76 lines (63 loc) · 1.99 KB
/
script.js
File metadata and controls
76 lines (63 loc) · 1.99 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const container = document.getElementById('sketchboard');
function makeRows(rows, cols) {
container.style.setProperty('--grid-rows', rows);
container.style.setProperty('--grid-cols', cols);
for (c = 0; c < (rows * cols); c++) {
let cell = document.createElement('div');
/*cell.innerText = (c + 1);*/
container.appendChild(cell).className = 'gridPiece';
cell.setAttribute('id', 'cell');
cell.addEventListener('click', function onClick(event) {
const deColores = ['#CCFF00', '#AAF0D1', '#66FF66', '#FF6EFF', '#FF9933', '#FFFF66', '#FF355E', '#FF00CC', '#50BFE6', ]
const randomColor = deColores[Math.floor(Math.random() * deColores.length)];
cell.style.backgroundColor = randomColor;
/*change so that it selects from a predetermined array of 'neon' colors*/
const clear = document.getElementById('clearButton');
clear.addEventListener('click', function onClick(event) {
cell.style.backgroundColor = 'black';
});
});
};
};
function wipeGrid() {
const grid = document.querySelectorAll('.gridPiece');
grid.forEach(grid => {
grid.remove();
});
}
const gridSize = document.getElementById('size-select');
gridSize.addEventListener('change', (e) => {
let selector = e.target.value;
switch (selector) {
case '8':
wipeGrid();
makeRows(8,8);
break;
case '16':
wipeGrid();
makeRows(16,16);
break;
case '32':
wipeGrid();
makeRows(32,32);
break;
case '50':
wipeGrid();
makeRows(50,50);
break;
default:
console.log('Something went wrong.')
}
});
/*
Clear Button
1. Add event listener to button
2. Query select for all by id cell
3. When clicked, change background color to rgb(0,0,0)
*/
/*
Grid Size Selector
1. Add Event listener
2. When id of selection clicked
run makeRows() to match selection
*/