log + drawLine
This commit is contained in:
parent
e747c0b060
commit
9e2e5ce581
6 changed files with 70 additions and 3 deletions
24
packages/core/drawLine.mjs
Normal file
24
packages/core/drawLine.mjs
Normal 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;
|
||||
Loading…
Add table
Add a link
Reference in a new issue