log + drawLine

This commit is contained in:
Felix Roos 2022-04-23 23:28:43 +02:00
parent e747c0b060
commit 9e2e5ce581
6 changed files with 70 additions and 3 deletions

View file

@ -0,0 +1,24 @@
import { gcd } from './fraction.mjs';
function drawLine(pat) {
let s = '';
let c = 0;
while (s.length < 60) {
const haps = pat.queryArc(c, c + 1);
const durations = haps.map((hap) => hap.duration);
const totalSlots = gcd(...durations).inverse();
haps.forEach((hap) => {
const duration = hap.whole.end.sub(hap.whole.begin);
const slots = totalSlots.mul(duration);
s += Array(slots.valueOf())
.fill()
.map((_, i) => (!i ? hap.value : '-'))
.join('');
});
s += '|';
++c;
}
return s;
}
export default drawLine;