-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
73 lines (54 loc) · 1.81 KB
/
script.js
File metadata and controls
73 lines (54 loc) · 1.81 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
let currentColor = 'black';
let currentSize = 16;
const gridcontainer = document.getElementById('gridcontainer');
makeGrid(currentSize);
//===Make the actual grid
function makeGrid(numDivs) {
gridcontainer.style.gridTemplateColumns = `repeat(${numDivs}, 1fr)`;
gridcontainer.style.gritTemplateRows = `repeat(${numDivs}, 1fr)`;
for (let d = 0; d < numDivs * numDivs; d++) {
let squares = document.createElement('div');
gridcontainer.appendChild(squares);
squares.addEventListener('mouseover', colorHover);
}
};
//===Change of color setting
function colorHover() {
if (currentColor === 'black') {
this.style.backgroundColor = 'black';
} else if (currentColor === 'random1') {
this.style.backgroundColor = chooseRandom1();
} else if (currentColor === 'random2') {
this.style.backgroundColor = chooseRandom2();
} else if (currentColor === 'erase') {
this.style.backgroundColor = 'white';
}
};
function setColor(colorChoice) {
return currentColor = colorChoice;
};
function chooseRandom1() {
let choose = ['#1affed', '#00ffeb', '#1af8ff', '#1affd6', '#1a6fff', '#22fb77'
, '#13cee0', '#3791ff', '#7155fc', '#8e2efc'];
return choose[Math.floor(Math.random() * choose.length)];
};
function chooseRandom2() {
let choose = ['#9dad86', '#9eb878', '#94d465', '#9bba59', '#af94c5', '#984adc'
, '#c096e5', '#ab8ec4', 'a9dca5#', '#d2e8d0'];
return choose[Math.floor(Math.random() * choose.length)];
};
//Clear or reload board
function clearIt() {
gridcontainer.innerHTML = '';
makeGrid(currentSize);
};
function reloadIt() {
gridcontainer.innerHTML = '';
};
//Change grid-square size
function changeCurrentSize(value) {
let currentSize;
currentSize = value;
reloadIt();
makeGrid(currentSize);
};