-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
71 lines (62 loc) · 1.62 KB
/
script.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const container = document.getElementById('container');
let rows = 16;
let cell;
let color = "black";
// Create grid function
function createGrid (row) {
container.textContent = "";
container.style.gridTemplateColumns = `repeat(${row}, 1fr)`;
let square = row * row;
for (let i=0; i<square; i++) {
cell = document.createElement('div');
cell.classList.add("content");
container.appendChild(cell);
}
}
// Initial grid load
createGrid(rows);
// Change size
function changeSize() {
rows = prompt("Enter how many rows you want between 1 and 64");
createGrid(rows);
cellDraw(color);
}
// Change to black
function black() {
color = "black";
cellDraw(color);
}
// Change to rainbow
function rainbow() {
color = "rainbow";
cellDraw(color);
}
// Get random numbers
function gR(min, max) {
return Math.random() * (max - min) + min;
}
// Draw cells function
function cellDraw (tint) {
if (tint === "black") {
cell = document.getElementsByClassName('content');
for (let i=0; i<cell.length; i++) {
cell[i].addEventListener("mouseenter", (e) => {
e.target.style.backgroundColor = "black";
});
}
}
else {
cell = document.getElementsByClassName('content');
for (let i=0; i<cell.length; i++) {
cell[i].addEventListener("mouseenter", (e) => {
e.target.style.backgroundColor = "rgb(" + gR(0,266) + "," + gR(0,266) + "," + gR(0,266) + ")";
});
}
}
}
// Reset button
function reset() {
window.location.reload();
}
// Paint black
cellDraw(color);