-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
104 lines (94 loc) · 3.39 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
const div = document.querySelector(".grid");
let size = 16; //default size of grid
for (let i = 0; i < 16; i++) {
const newdiv = document.createElement("div");
for (let l = 0; l < 16; l++) {
const childdiv = document.createElement("div");
newdiv.appendChild(childdiv);
childdiv.addEventListener("mouseover", function () {
childdiv.style.backgroundColor = "#C9D5B5";
});
childdiv.classList.add("inside");
}
newdiv.classList.add("container");
div.appendChild(newdiv);
}
let choice;
const butt = document.querySelector("button");
const rain = document.querySelector(".rain");
const col = document.querySelector(".col");
const erase = document.querySelector(".erase");
erase.addEventListener("click",function ()
{
const ins = document.querySelectorAll(".inside");
ins.forEach(function (childdiv)
{
childdiv.addEventListener("mouseover", function () {
childdiv.style.backgroundColor="white";
})})});
rain.addEventListener("click", function(){
const ins = document.querySelectorAll(".inside");
ins.forEach(function (childdiv)
{
childdiv.addEventListener("mouseover", function () {
r1 = Math.floor(Math.random()*255);
r2 = Math.floor(Math.random()*255);
r3 = Math.floor(Math.random()*255);
childdiv.style.backgroundColor=`rgb(${r1},${r2},${r3})`;
})})});
col.addEventListener("click", function(){
const ins = document.querySelectorAll(".inside");
ins.forEach(function (childdiv)
{
childdiv.addEventListener("mouseover", function () {
childdiv.style.backgroundColor=`#C9D5B5`;
})})});
butt.addEventListener("click", function () {
choice = +(prompt("Enter the size of one side of the grid: "));
while(choice>100)
{
alert("The maximum size of the grid is 100!");
choice = +(prompt("Enter the size of one side of the grid: "));
}
while(choice<=0)
{
alert("Please use an appropriate size");
choice = +(prompt("Enter the size of one side of the grid: "));
}
for (let i = 0; i < size; i++) {
const newdiv = document.querySelector(".container");
for (let l = 0; l < size; l++) {
const childdiv = document.querySelector(".inside");
childdiv.remove();
}
newdiv.remove();
}
size = 640 / choice;
for (let i = 0; i < choice; i++) {
const newdiv = document.createElement("div");
for (let l = 0; l < choice; l++) {
const childdiv = document.createElement("div");
newdiv.appendChild(childdiv);
childdiv.addEventListener("mouseover", function () {
childdiv.style.backgroundColor = "#C9D5B5";
});
childdiv.classList.add("inside");
childdiv.style.height = `${size}px`;
childdiv.style.width = `${size}px`;
childdiv.style.maxWidth = `${size}px`;
}
newdiv.classList.add("container");
newdiv.style.height = `${size}px`;
div.appendChild(newdiv);
}
size = choice;
// const ins = document.querySelectorAll(".inside");
// ins.forEach(function (i) {
// i.style.height = `${choice}px`;
// i.style.width = `${choice}px`;
// })
// //const con = document.querySelectorAll(".container");
// con.forEach(function (i) {
// i.style.height = `${choice}px`;
// })
});