/ interactive_tutorials / hardening_softening
Sign in
interactive_tutorials / hardening_softening
hardening_softening / app / main.js
69 lines · 3.0 KBCodeBlameHistory
7212d95Hardening and softening tutorialJeremy Magland 1// Interactive slides for the hardening and softening tutorial. The slide text
2// is in index.html (from recipe.md); this file sets up each slide's
3// interactive panel and starts the deck. The reusable parts are in js/.
5import { initDeck } from './js/deck.js';
6import { createOscillatorPage } from './js/oscillator-page.js';
7import { DRIVEN_PRESETS } from './driven-presets.js';
8import { createPhasePage } from './js/phase-page.js';
9import { createResponsePlot } from './js/response-plot.js';
10import { PHASE_DEFAULT, PHASE_PRESETS } from './phase-presets.js';
12const oscillator = (id, options) => createOscillatorPage({
13 container: document.querySelector(`#${id} [data-oscillator]`),
14 ...options,
15});
17// alpha = 3e7 s^-2 hardens the spring strongly at the Duffing slides' default
18// x0 = 0.4 and f0: alpha x0^2 is about 2.5 (2 pi f0)^2, raising the pitch
19// from 220 to about 370 Hz.
20// delta = 2 s^-1 lets the sound decay over a few seconds (amplitude e^(-t)),
21// so the pitch glide as the swing shrinks is easy to hear.
22// The driven slide's defaults are from the recipe, except F (not given):
23// F = 5e4 s^-2 at 220 Hz from rest builds up to a swing of about 0.2, where
24// the hardening spring has detuned it from the drive.
25// On the Duffing slides the linear stiffness can be negative (a double
26// well): f0's slider goes negative, down to -1000 Hz, where alpha at its
27// slider maximum still keeps the wells within reach (see oscillator-page.js).
28const signedFreq = { freq: { min: -1000, unit: '(negative: <i>k</i> &lt; 0)' } };
30const sims = {
31 harmonic: oscillator('harmonic', {
32 params: { x0: 0.2, freq: 220 },
33 labels: ['x', 'm', 'k'],
34 }),
35 duffing: oscillator('duffing', {
36 sliders: signedFreq,
37 params: { x0: 0.4, freq: 220, alpha: 3e7 },
38 labels: ['x', 'm', 'k', 'beta'],
39 }),
40 damped: oscillator('damped', {
41 sliders: signedFreq,
42 params: { x0: 0.4, freq: 220, alpha: 3e7, delta: 2 },
43 labels: ['x', 'm', 'k', 'beta', 'c'],
44 damper: true,
45 }),
46 driven: oscillator('driven', {
47 sliders: signedFreq,
48 presets: DRIVEN_PRESETS,
49 presetContainer: document.querySelector('#driven [data-presets]'),
50 params: { x0: 0, freq: 220, alpha: 3e7, delta: 0, F: 5e4, drive: 220 },
51 labels: ['x', 'm', 'k', 'beta', 'c', 'F'],
52 damper: true,
53 }),
54 // Lab (experimental, outside the recipe; see lab.md). Phase space: starts on
55 // a double well, undamped, driven at 490 Hz; damping up to 200, so a damped
56 // orbit spirals in over a few turns; f0 down to -1000 Hz, as above
57 orbits: createPhasePage({
58 controls: document.querySelector('#orbits [data-phase-controls]'),
59 container: document.querySelector('#orbits [data-phase]'),
60 params: { ...PHASE_DEFAULT },
61 sliders: { ...signedFreq, alpha: { minFor: null }, delta: { max: 200 } },
62 presets: PHASE_PRESETS,
63 instruments: true,
64 }),
65 // the instruments' frequency responses, on the lab's write-up slide
66 how: createResponsePlot(document.querySelector('#how canvas.responses'), { names: ['wood', 'plate', 'marimba', 'harp', 'bell'] }),
67};
69initDeck({ sims });
↑↓ move↵openescclose