-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscripts.js
More file actions
executable file
·66 lines (53 loc) · 2.04 KB
/
scripts.js
File metadata and controls
executable file
·66 lines (53 loc) · 2.04 KB
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
document.addEventListener("DOMContentLoaded", function() {
const matrixContainer = document.getElementById("matrix");
const symbolDataOutput = document.getElementById("symbolData");
const clearBtn = document.getElementById("clearBtn");
const invertBtn = document.getElementById("invertBtn");
const rows = 8;
const cols = 5;
for (let i = 0; i < rows; i++) {
for (let j = 0; j < cols; j++) {
const button = document.createElement("button");
button.dataset.row = i;
button.dataset.col = j;
button.addEventListener("click", toggleBit);
matrixContainer.appendChild(button);
}
}
clearBtn.addEventListener("click", clearMatrix);
invertBtn.addEventListener("click", invertMatrix);
updateSymbolData();
function toggleBit(event) {
const button = event.target;
button.classList.toggle("active");
updateSymbolData();
}
function updateSymbolData() {
const symbolData = [];
for (let i = 0; i < rows; i++) {
let rowBits = 0;
for (let j = 0; j < cols; j++) {
const button = document.querySelector(`button[data-row="${i}"][data-col="${j}"]`);
if (button.classList.contains("active")) {
rowBits |= (1 << (cols - 1 - j));
}
}
symbolData.push(rowBits);
}
displaySymbolData(symbolData);
}
function displaySymbolData(data) {
// symbolDataOutput.textContent = data.map(num => num.toString(2).padStart(cols, '0')).join('\n');
symbolDataOutput.textContent = `byte custom[8] = {\n ${data.map(byte => 'B' + byte.toString(2).padStart(cols, '0')).join(',\n ')}\n};`;
}
function clearMatrix() {
const buttons = matrixContainer.querySelectorAll("button");
buttons.forEach(button => button.classList.remove("active"));
updateSymbolData();
}
function invertMatrix() {
const buttons = matrixContainer.querySelectorAll("button");
buttons.forEach(button => button.classList.toggle("active"));
updateSymbolData();
}
});