Phonon Vibrational Modes
by Chantal Roth
HTML
<div class="main-layout">
<div class="controls-sidebar">
<h2>Phonon Simulator (Modes)</h2>
<div class="view-selector">
<h3>View Mode</h3>
<div class="radio-group">
<input type="radio" id="viewSingle" name="viewMode" value="single" checked>
<label for="viewSingle">Single Interactive (Energy)</label>
</div>
<div class="radio-group">
<input type="radio" id="viewStacked" name="viewMode" value="stacked">
<label for="viewStacked">Stacked Modes</label>
</div>
</div>
<div id="singleControls" class="control-section">
<h3>Interactive Controls</h3>
<div class="control-group">
<label>Vibration Mode (k)</label>
<input type="range" id="modeSlider" min="1" max="8" value="1" step="1">
<span id="modeDisplay" class="value-display">n = 1</span>
</div>
<div hidden="true" class="control-group highlight-group">
<label>Excitation Energy</label>
<input type="range" id="ampSlider" min="0" max="20" value="6" step="0.1">
<span id="ampDisplay" class="value-display">Level: 0 (Zero Point)</span>
</div>
</div>
<div id="stackedExplainer" class="control-section" style="display:none;">
<h3>Stacked View</h3>
<p>This view illustrates the <strong>Spatial Quantization</strong> defined by the boundaries</p>
<p>Each row is a normal mode with a different wavevector k.</p>
</div>
</div>
<div class="canvas-container">
<canvas id="simCanvas"></canvas>
<div class="legend">
<span style="color:#ff4757">■</span> Atoms
<span style="color:#2ed573">〰</span> Springs
<span style="color:#70a1ff">---</span> Wave Envelope
</div>
</div>
</div>
CSS
:root {
--bg-main: #0b0e11;
--bg-panel: #1e272e;
--text-bright: #d2dae2;
--text-dim: #808e9b;
--accent-orange: #ffa502;
--accent-red: #ff4757;
--accent-green: #2ed573;
}
body {
background-color: #2f3640;
color: var(--text-bright);
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
margin: 0;
padding: 20px;
display: flex;
justify-content: center;
min-height: 100vh;
box-sizing: border-box;
}
.main-layout {
display: flex;
background: var(--bg-main);
border-radius: 12px;
box-shadow: 0 20px 50px rgba(0,0,0,0.6);
overflow: hidden;
width: 1000px;
max-width: 100%;
border: 1px solid #485460;
}
.controls-sidebar {
padding: 25px;
width: 300px;
background: var(--bg-panel);
border-right: 1px solid #485460;
display: flex;
flex-direction: column;
gap: 25px;
}
h2 { margin: 0; color: var(--accent-orange); font-size: 1.4rem;}
h3 { margin: 0 0 15px 0; color: var(--text-bright); font-size: 1.1rem; border-bottom: 1px solid #485460; padding-bottom: 5px;}
.control-section {
background: rgba(0,0,0,0.2);
padding: 15px;
border-radius: 8px;
}
.radio-group { margin-bottom: 10px; display: flex; align-items: center;}
.radio-group input { margin-right: 10px; }
.radio-group label { cursor: pointer; }
.control-group { display: flex; flex-direction: column; gap: 8px; margin-bottom: 20px;}
.control-group label { font-size: 0.9rem; font-weight: 600; color: var(--text-dim); }
.value-display { font-family: monospace; color: var(--accent-orange); align-self: flex-end;}
input[type="range"] { width: 100%; cursor: pointer; accent-color: var(--accent-orange);}
.highlight-group {
border-left: 3px solid var(--accent-orange);
padding-left: 10px;
}
/* Toggle Switch styling */
.toggle-container { display: flex; align-items: center; gap: 12px; margin-bottom: 8px;}
.switch { position: relative; display: inline-block; width: 40px;...
JavaScript
const canvas = document.getElementById('simCanvas');
const ctx = canvas.getContext('2d');
// === Configuration State ===
const state = {
viewMode: 'single', // 'single' or 'stacked'
numAtoms: 21, // Odd number looks better for symmetry
singleModeN: 1, // The 'n' in single view
energyLevel: 5, // The quantum excitation level (0, 1, 2...)
isQuantum: false, // Toggle for energy quantization
time: 0
};
// === DOM References ===
const elements = {
viewRadios: document.getElementsByName('viewMode'),
singleControls: document.getElementById('singleControls'),
stackedExplainer: document.getElementById('stackedExplainer'),
modeSlider: document.getElementById('modeSlider'),
modeDisplay: document.getElementById('modeDisplay'),
//ampSlider: document.getElementById('ampSlider'),
ampDisplay: document.getElementById('ampDisplay'),
};
// === Initialization & Events ===
function init() {
resize();
window.addEventListener('resize', resize);
// View Mode Switching
Array.from(elements.viewRadios).forEach(radio => {
radio.addEventListener('change', (e) => {
state.viewMode = e.target.value;
updateUIVisibility();
});
});
// Single Mode Controls
elements.modeSlider.addEventListener('input', (e) => {
state.singleModeN = parseInt(e.target.value);
elements.modeDisplay.innerText = `n = ${state.singleModeN}`;
});
// Energy Slider (The crucial part for explanation)
// elements.ampSlider.addEventListener('input', handleEnergyInput);
// Initial setup
updateUIVisibility();
// handleEnergyInput({ target: elements.ampSlider }); // Set initial energy state
animate();
}
function resize() {
// Make canvas sharper on high-DPI displays
const dpr = window.devicePixelRatio || 1;
const rect = canvas.parentElement.getBoundingClientRect();
canvas.width = rect.width * dpr;
...