Published
Edited
Sep 27, 2022
16 forks
85 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
presets = [
{
name: "Love is in the air (Intro)",
patterns: [
{ pulses: 3, steps: 8, play: kick },
{ pulses: 1, steps: 8, rotation: 4, play: clap },
{ pulses: 5, steps: 8, rotation: 4, play: hihat },
],
bpm: 122,
timeDivision: 4
},
{
name: "Disco",
patterns: [
{ pulses: 2, steps: 8, play: kick },
{ pulses: 1, steps: 8, rotation: 4, play: snare },
{ pulses: 7, steps: 8, rotation: 4, play: hihat },
],
bpm: 120,
timeDivision: 4
},
{
name: "Custom",
patterns: [
{ pulses: 1, steps: 6, rotation: 0, play: kick },
{ pulses: 1, steps: 6, rotation: 3, play: snare },
{ pulses: 2, steps: 6, rotation: 2, play: hihat },
{ pulses: 1, steps: 7, rotation: 6, play: clap },
{ pulses: 1, steps: 7, rotation: 4, play: rim },
{ pulses: 1, steps: 4, rotation: 1, play: rim },
],
bpm: 120,
timeDivision: 3
}
]
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
step_1 = {
let { a, b, k, m } = step_0;
a += b;
m -= k;
return { a, b, k, m }
}
Insert cell
Insert cell
step_2 = {
let { a, b, k, m } = step_1;
let cpy, tmp;

cpy = a;
a += b;
b = cpy;
tmp = k;
k = m;
m = tmp - m;
return { a, b, k, m }
}
Insert cell
Insert cell
step_3 = {
let { a, b, k, m } = step_2;
let cpy, tmp;

cpy = a;
a += b;
b = cpy;
tmp = k;
k = m;
m = tmp - m;
return { a, b, k, m }
}
Insert cell
Insert cell
step_4 = {
let { a, b, k, m } = step_3;
let rhythm = "";
while (k > 0) (rhythm += a, --k);
while (m > 0) (rhythm += b, --m);

return rhythm;
}
Insert cell
Insert cell
function E(pulses, steps) {
if (pulses > steps) pulses = steps;

// step 0
let a = "1";
let b = "0";
let k = pulses;
let m = steps - pulses;

let cpy, tmp;

do {
cpy = a;
a += b;
if (k <= m) { // step 1
m -= k;
} else { // step 2, 3
b = cpy;
tmp = k;
k = m;
m = tmp - m;
}
} while (m > 1 & k > 1);

// step 4
let rhythm = "";
while (k > 0) (rhythm += a, --k);
while (m > 0) (rhythm += b, --m);
return rhythm;
}
Insert cell
Insert cell
Insert cell
function euclid(m, k) {
if (k === 0) return m;
else return euclid(k, m % k);
}
Insert cell
Insert cell
function eucildOriginal(m, k) {
while (m !== k) {
if (m > k) {
m -= k;
} else {
k -= m;
}
}
return m;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more