Published
Edited
Jan 28, 2020
1 star
Insert cell
Insert cell
mutable segments = Array.from(new Array(16), () => ({v: 0, w: 0}))
Insert cell
Insert cell
Insert cell
hits = d3.range(mutable segments.length).map(i => Math.random() < .5 ? 50+Math.random()*20 : -1)
// d3.range(mutable segments.length).map((i) => {return i == 4 ? 60 : -1})
Insert cell
Insert cell
// mutable segments[5].v = 2
Insert cell
Insert cell
mutable I = 1 // or ~80 velocity
Insert cell
Insert cell
env = ({attack: .001, decay: 0.5, sustain: .1, release: 1.4})
// ({attack: .02, decay: 0.2, sustain: .0, release: 1.0})
Insert cell
// https://observablehq.com/@maddievision/song-player
synth = {
let polyphony = mutable segments.length,
// env = {attack: .1, decay: .4, sustain: .01, release: .01},
volume = -10
var synth = new Tone.PolySynth(polyphony, Tone.Synth, {
oscillator: {type: 'sine'},
// noise: {type: 'white'},
envelope: env,
volume
}).toMaster();
try {
yield synth;
yield invalidation;
} finally {
synth.dispose();
}
}
Insert cell
t = {
let t = mutable pause
// mutable I = 2
try {
yield t
while (true) {
mutable segments.forEach((u, i) => {
let {v,w} = u, // using a singly linked list topology
forcing = i == 0 ? 0 : mutable segments[i-1].v //+ mutable segments[i+1].v
// https://en.wikipedia.org/wiki/FitzHugh%E2%80%93Nagumo_model
let dv = (v*1.5 - v*v*v*.3 - w + forcing) * 1.8,
dw = (v + .5 - .5*w) * 1.2
u.v += dv/20
u.w += dw/20
if (i == 0 && mutable I != 0) u.v = mutable I
})
mutable segments = mutable segments
mutable I = 0
yield Promises.delay(10, ++t)
}
}
finally {
mutable pause = t
}
}
Insert cell
mutable pause = 0
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more