-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgrid.js
More file actions
26 lines (22 loc) · 806 Bytes
/
grid.js
File metadata and controls
26 lines (22 loc) · 806 Bytes
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
const grid = document.getElementById('grid-container');
let lights = [];
function initGrid() {
grid.innerHTML = '';
lights = Array.from({ length: WIDTH }, () => Array(HEIGHT));
for (let y = 0; y < HEIGHT; y++) {
for (let x = 0; x < WIDTH; x++) {
const div = document.createElement('div');
div.className = 'pixel';
div.onmousedown = () => pixelClicked(x, y);
div.onmouseenter = (e) => { if (e.buttons === 1) pixelEnteredClicked(x, y); };
div.onmouseup = () => pixelUnclicked(x, y)
div.style.backgroundColor = "#000000"
grid.appendChild(div);
lights[x][y] = div;
}
}
}
function updateGridPixel(x, y, color) {
lights[x][y].style.backgroundColor = `#${color}`;
}
initGrid();