-
Notifications
You must be signed in to change notification settings - Fork 0
/
scripts.js
160 lines (91 loc) · 2.99 KB
/
scripts.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
// console.log('<h1>Hello</h1>')
// const para = document.createAttribute('p')
// const test = document.querySelector('#test')
// test.textContent = 'Helllooo'
// creating grid
// getting slider value
const sliderValue = document.querySelector('#slider');
const para = document.querySelector('span');
para.textContent = '16x16';
sliderValue.addEventListener('input', () => {
para.textContent = `${sliderValue.value}x${sliderValue.value}`;
grid(sliderValue.value);
});
const container = document.querySelector('#container');
// let size = sliderValue.value //prompt('What container size do you want 16-64?')
let gridSize = 600;
// console.log(gridSize/size);
// console.log(sliderValue.value);
function grid(size){
container.innerHTML='';
for (let i = 0; i < size*size;i++) {
let square = document.createElement('div');
square.classList.add('box');
// square.textContent = `${i}`;
square.style.width = (gridSize/(size * 1) - 2).toString() + 'px';
square.style.height = (gridSize/(size * 1) - 2).toString() + 'px';
container.appendChild(square);
square.addEventListener('mouseover', function (e) {
e.target.style.background = 'black';
});
};
};
grid(16)
let size = 50;
// Button Controls Below:
const children = container.childNodes;
// Random Color:
function random(){
randomColor='#'+Math.floor(Math.random()*16777215).toString(16);
return randomColor
}
const rgb = document.querySelector('#rgb');
rgb.addEventListener('click', () => {
for (let i=0;i<size*size;i++){
if (children[i] === undefined){
continue;
} else {
children[i].addEventListener('mouseover', function(e){
e.target.style.background = random();
});
};
};
});
//Black Button:
const black = document.querySelector('#black');
black.addEventListener('click', () => {
for (let i = 0; i < size*size;i++){
if (children[i] === undefined){
continue;
} else {
children[i].addEventListener('mouseover', function(e){
e.target.style.background = 'black';
});
};
};
});
//Reset Button:
const reset = document.querySelector('#reset');
reset.addEventListener('click', () => {
children.forEach(child => {
child.style.backgroundColor = 'white';
});
});
// function getRandomColor(){
// let letters = '0123456789ABCDEF';
// let color = '#';
// for (var i = 0; i < 6; i++) {
// color += letters[Math.floor(Math.random() * 16)];
// };
// return color;
// };
// const rgb = document.querySelector('#rgb');
// rgb.addEventListener('click', function(){
// let cell = container.childNodes;
// for (let i = 0; i <= size*size; i++) {
// cell[i].addEventListener('mouseover', function(e){
// e.target.style.backgroundColor = getRandomColor();
// console.log('should worked')
// });
// };
// });