-
Notifications
You must be signed in to change notification settings - Fork 0
/
designs.js
42 lines (27 loc) · 1.04 KB
/
designs.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
// Select color input
var chooseColor = document.getElementById('colorPicker');
var shape = document.getElementById('pixelCanvas');
var height = document.getElementById('inputHeight').value;
var width = document.getElementById('inputWidth').value;
// Select size input
var chooseSize = document.getElementById('sizePicker');
chooseSize.addEventListener('click', (event) => {
event.preventDefault();
const tempheight = document.getElementById('inputHeight').value;
const tempwidth = document.getElementById('inputWidth').value;
shape.firstElementChild.remove();
makeGrid(tempheight, tempwidth);
});
// When size is submitted by the user, call makeGrid()
function makeGrid(height, width) {
for (let r = 0; r < height; r++) {
let row = shape.insertRow(r);
for (let c = 0; c < width; c++) {
let cell = row.insertCell(c);
cell.addEventListener('click', (event) => {
cell.style.backgroundColor = chooseColor.value;
});
}
}
}
makeGrid(height, width);