Changed around line 1
+ document.addEventListener('DOMContentLoaded', function() {
+ const simulateButton = document.getElementById('simulate');
+ const highlightBox = document.querySelector('.highlight-box');
+ const stepText = document.getElementById('step-text');
+ let isAnimating = false;
+
+ function getMatrixValues(matrixId) {
+ const inputs = document.querySelectorAll(`#${matrixId} input`);
+ return Array.from(inputs).map(input => parseFloat(input.value));
+ }
+
+ function createResultMatrix() {
+ const container = document.querySelector('.result-matrix');
+ container.innerHTML = '';
+ container.style.display = 'grid';
+ container.style.gridTemplateColumns = 'repeat(2, 1fr)';
+ container.style.gap = '0.5rem';
+
+ for (let i = 0; i < 4; i++) {
+ const cell = document.createElement('div');
+ cell.className = 'result-cell';
+ cell.style.width = '60px';
+ cell.style.height = '60px';
+ cell.style.border = '2px solid #3498db';
+ cell.style.borderRadius = '5px';
+ cell.style.display = 'flex';
+ cell.style.alignItems = 'center';
+ cell.style.justifyContent = 'center';
+ cell.style.fontSize = '1.2rem';
+ cell.style.background = 'white';
+ container.appendChild(cell);
+ }
+ }
+
+ async function animateMultiplication() {
+ if (isAnimating) return;
+ isAnimating = true;
+
+ const matrixA = getMatrixValues('matrixA');
+ const matrixB = getMatrixValues('matrixB');
+ createResultMatrix();
+ const resultCells = document.querySelectorAll('.result-cell');
+
+ for (let i = 0; i < 2; i++) {
+ for (let j = 0; j < 2; j++) {
+ // Highlight current calculation
+ highlightBox.style.opacity = '1';
+ const result = matrixA[i*2] * matrixB[j] + matrixA[i*2+1] * matrixB[j+2];
+
+ stepText.textContent = `Calculating position (${i+1},${j+1}):
+ (${matrixA[i*2]} × ${matrixB[j]}) +
+ (${matrixA[i*2+1]} × ${matrixB[j+2]}) = ${result}`;
+
+ await new Promise(resolve => setTimeout(resolve, 1000));
+
+ resultCells[i*2 + j].textContent = result;
+ resultCells[i*2 + j].style.animation = 'fadeIn 0.5s ease-out';
+ }
+ }
+
+ highlightBox.style.opacity = '0';
+ stepText.textContent = 'Multiplication complete!';
+ isAnimating = false;
+ }
+
+ simulateButton.addEventListener('click', animateMultiplication);
+
+ // Input validation
+ document.querySelectorAll('input[type="number"]').forEach(input => {
+ input.addEventListener('input', function() {
+ if (this.value === '') this.value = '0';
+ });
+ });
+ });