Gadgety_Euclidean_Sequencer.../assets/js/bjorklund.js
2018-09-05 19:17:08 +02:00

38 lines
911 B
JavaScript

bjorklund(slots, pulses) {
var pattern = [],
count = [],
remainder = [pulses],
divisor = slots - pulses,
level = 0,
build_pattern = function(lv) {
if (lv == -1) {
pattern.push(0);
} else if (lv == -2) {
pattern.push(1);
} else {
for (var x = 0; x < count[lv]; x++) {
build_pattern(lv - 1);
}
if (remainder[lv]) {
build_pattern(lv - 2);
}
}
}
while (remainder[level] > 1) {
count.push(Math.floor(divisor / remainder[level]));
remainder.push(divisor % remainder[level]);
divisor = remainder[level];
level++;
}
count.push(divisor);
build_pattern(level);
return pattern.reverse();
},
assignEuclidean: function(a, b) {
this.euclideanList = this.bjorklund(a, b);
console.log(this.euclideanList);
}
}