-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEtch.js
88 lines (82 loc) · 2.65 KB
/
Etch.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
let board = document.querySelector('.Board');
let Body = document.querySelector('body');
function RemovePreviousGrid() {
let AllBoxes = document.querySelectorAll('.Box');
AllBoxes.forEach((EachBox) => board.removeChild(EachBox));
}
function MakeGrid(WidthofGrid) {
//First Remove Already Existing Grid
RemovePreviousGrid();
//Now Built New Grid
board.setAttribute("style", `grid-template-columns: repeat(${WidthofGrid}, 1fr);`);
for(var j = 0; j < WidthofGrid ; j++){
for(var i = 0 ; i < WidthofGrid ; i++)
{
let Div = document.createElement('div');
Div.classList.add('Box');
board.appendChild(Div);
}
}
//Set colorChange on MouseHover on New Grid
ResetBoard();
SetColorProperty(0,0,0);
}
Body.addEventListener('onload', MakeGrid(16)); // Setting Board to 16 x 16
// Set New Board on Users Choise
function ResizeBoard() {
let NewBoardSize
while(NewBoardSize == null){
NewBoardSize = prompt("Enter NUmber of Boxs per row");}
MakeGrid(NewBoardSize);
}
function SetColorProperty(R,G,B,Hex,WhichFormateToTake){
let AllBoxs = document.querySelectorAll('.Box');
if(WhichFormateToTake == 1){
AllBoxs.forEach(function(Box){
Box.addEventListener('mouseover' , () => Box.style.backgroundColor = `rgb(${R},${G},${B})`);
});
}
else
{
AllBoxs.forEach(function(Box){
Box.addEventListener('mouseover' , () => Box.style.backgroundColor = Hex);
});
}
}
function SetColorToRed(argument) {
RemoveEventListener();
SetColorProperty(255,0,0,0,1);
}
function EraseAllColorEffect(argument) {
RemoveEventListener();
SetColorProperty(255,255,255,0,1);
}
function SetColorToGreen(argument) {
RemoveEventListener();
SetColorProperty(0,128,0,0,1);
}
function SetColorOfUserChoise(argument) {
RemoveEventListener();
let UserChoise = document.querySelector('.SetColor').value;
SetColorProperty(0,0,0,UserChoise,0);
}
function SetColorEffectAtRandom() {
let AllBoxs = document.querySelectorAll('.Box');
AllBoxs.forEach(HelperFunction);
}
function HelperFunction(Box) {
Box.addEventListener('mouseover',() => Box.style.backgroundColor = `rgb(${Math.floor(Math.random() * 256)},${Math.floor(Math.random() * 256)},${Math.floor(Math.random() * 256)})`);
}
function RemoveEventListener(){
let AllBoxs = document.querySelectorAll('.Box');
AllBoxs.forEach(function(Box){
Box.removeEventListener('mouseover',() => Box.style.backgroundColor = `rgb(${Math.floor(Math.random() * 256)},${Math.floor(Math.random() * 256)},${Math.floor(Math.random() * 256)})`);
});
}
function ResetBoard() {
let AllBoxs = document.querySelectorAll('.Box');
AllBoxs.forEach(function(Box){
Box.style.backgroundColor = "rgb(256,256,256)";
});
SetColorProperty(0,0,0,0,1);
}