// Draw metronomes on the canvas function drawMetronomes() { console.log("Drawing metronomes"); const canvas = document.getElementById('metronomeCanvas'); if (!canvas) { console.error("Metronome canvas not found!"); return; } const ctx = canvas.getContext('2d'); const width = canvas.width; const height = canvas.height; ctx.clearRect(0, 0, width, height); // Background ctx.fillStyle = '#1e1e1e'; ctx.fillRect(0, 0, width, height); // Draw title ctx.font = '14px Arial'; ctx.fillStyle = '#e0e0e0'; ctx.textAlign = 'center'; ctx.fillText('Oscillators as Metronomes', width / 2, 20); const numOscillators = phases.length; const colors = ['#4bc0c0', '#36a2eb', '#ffce56', '#ff6384', '#9966ff']; const metronomesWidth = width - 40; const metronomeWidth = metronomesWidth / numOscillators; const metronomeHeight = height * 0.6; const baseY = height * 0.85; // Draw each metronome for (let i = 0; i < numOscillators; i++) { const centerX = 20 + (i * metronomeWidth) + (metronomeWidth / 2); // Draw metronome base ctx.fillStyle = '#333'; ctx.fillRect(centerX - 15, baseY, 30, 10); ctx.fillStyle = '#222'; ctx.fillRect(centerX - 20, baseY + 10, 40, 5); // Draw metronome body ctx.fillStyle = colors[i]; ctx.fillRect(centerX - 10, baseY - metronomeHeight, 20, metronomeHeight); // Draw metronome pendulum const pendulumLength = metronomeHeight * 0.8; const pendulumAngle = Math.PI / 3 * Math.sin(phases[i]); // Map phase to pendulum swing const pendulumEndX = centerX + pendulumLength * Math.sin(pendulumAngle); const pendulumEndY = baseY - metronomeHeight + pendulumLength * Math.cos(pendulumAngle); ctx.beginPath(); ctx.moveTo(centerX, baseY - metronomeHeight + 10); ctx.lineTo(pendulumEndX, pendulumEndY); ctx.strokeStyle = '#e0e0e0'; ctx.lineWidth = 2; ctx.stroke(); // Draw pendulum weight ctx.beginPath(); ctx.arc(pendulumEndX, pendulumEndY, 6, 0, 2 * Math.PI); ctx.fillStyle = '#e0e0e0'; ctx.fill(); // Draw oscillator number ctx.font = '16px Arial'; ctx.fillStyle = '#e0e0e0'; ctx.textAlign = 'center'; ctx.fillText((i + 1).toString(), centerX, baseY - metronomeHeight / 2); // Draw sync indicator (small dot if in sync with reference oscillator) let phaseDiff = phases[i] - phases[0]; if (phaseDiff < -Math.PI) phaseDiff += 2 * Math.PI; if (phaseDiff > Math.PI) phaseDiff -= 2 * Math.PI; if (Math.abs(phaseDiff) < 0.3 || (i === 0)) { ctx.beginPath(); ctx.arc(centerX, baseY - metronomeHeight - 10, 5, 0, 2 * Math.PI); ctx.fillStyle = '#4CAF50'; ctx.fill(); } } // Draw chimera state indicator const isChimera = detectChimeraState(phases); if (isChimera) { ctx.font = '14px Arial'; ctx.fillStyle = '#ff6666'; ctx.textAlign = 'center'; ctx.fillText('Chimera State', width / 2, height - 15); } }