// Interactive slides for the hardening and softening tutorial. The slide text // is in index.html (from recipe.md); this file sets up each slide's // interactive panel and starts the deck. The reusable parts are in js/. import { initDeck } from './js/deck.js'; import { createOscillatorPage } from './js/oscillator-page.js'; import { DRIVEN_PRESETS } from './driven-presets.js'; import { createPhasePage } from './js/phase-page.js'; import { createResponsePlot } from './js/response-plot.js'; import { PHASE_DEFAULT, PHASE_PRESETS } from './phase-presets.js'; const oscillator = (id, options) => createOscillatorPage({ container: document.querySelector(`#${id} [data-oscillator]`), ...options, }); // alpha = 3e7 s^-2 hardens the spring strongly at the Duffing slides' default // x0 = 0.4 and f0: alpha x0^2 is about 2.5 (2 pi f0)^2, raising the pitch // from 220 to about 370 Hz. // delta = 2 s^-1 lets the sound decay over a few seconds (amplitude e^(-t)), // so the pitch glide as the swing shrinks is easy to hear. // The driven slide's defaults are from the recipe, except F (not given): // F = 5e4 s^-2 at 220 Hz from rest builds up to a swing of about 0.2, where // the hardening spring has detuned it from the drive. // On the Duffing slides the linear stiffness can be negative (a double // well): f0's slider goes negative, down to -1000 Hz, where alpha at its // slider maximum still keeps the wells within reach (see oscillator-page.js). const signedFreq = { freq: { min: -1000, unit: '(negative: k < 0)' } }; const sims = { harmonic: oscillator('harmonic', { params: { x0: 0.2, freq: 220 }, labels: ['x', 'm', 'k'], }), duffing: oscillator('duffing', { sliders: signedFreq, params: { x0: 0.4, freq: 220, alpha: 3e7 }, labels: ['x', 'm', 'k', 'beta'], }), damped: oscillator('damped', { sliders: signedFreq, params: { x0: 0.4, freq: 220, alpha: 3e7, delta: 2 }, labels: ['x', 'm', 'k', 'beta', 'c'], damper: true, }), driven: oscillator('driven', { sliders: signedFreq, presets: DRIVEN_PRESETS, presetContainer: document.querySelector('#driven [data-presets]'), params: { x0: 0, freq: 220, alpha: 3e7, delta: 0, F: 5e4, drive: 220 }, labels: ['x', 'm', 'k', 'beta', 'c', 'F'], damper: true, }), // Lab (experimental, outside the recipe; see lab.md). Phase space: starts on // a double well, undamped, driven at 490 Hz; damping up to 200, so a damped // orbit spirals in over a few turns; f0 down to -1000 Hz, as above orbits: createPhasePage({ controls: document.querySelector('#orbits [data-phase-controls]'), container: document.querySelector('#orbits [data-phase]'), params: { ...PHASE_DEFAULT }, sliders: { ...signedFreq, alpha: { minFor: null }, delta: { max: 200 } }, presets: PHASE_PRESETS, instruments: true, }), // the instruments' frequency responses, on the lab's write-up slide how: createResponsePlot(document.querySelector('#how canvas.responses'), { names: ['wood', 'plate', 'marimba', 'harp', 'bell'] }), }; initDeck({ sims });