Fixed volume lines

This commit is contained in:
Benjamin Bädorf 2019-06-08 21:20:13 +02:00
parent ee60abc62b
commit 7194376bc8

View file

@ -58,7 +58,6 @@ async function main() {
spectrum.reverse();
const volume = getRMS(spectrum);
const pitch = getPitch(spectrum, volume);
lines.unshift({
@ -93,17 +92,7 @@ async function main() {
sketch.colorMode(sketch.HSL, 255);
};
let shouldDraw = 0;
sketch.draw = () => {
shouldDraw += 1;
if (shouldDraw > 0) {
if (shouldDraw > 3) {
shouldDraw = -1;
}
return;
}
sketch.background(sketch.color(0, 0, 0));
for (let l = 0; l < lines.length; l++) {
const lineBaseHeight = baseHeight - (l * LINE_MARGIN);
@ -112,14 +101,16 @@ async function main() {
sketch.stroke(((line.pitch - minPitch) / (maxPitch - minPitch)) * 255);
sketch.strokeWeight(1);
sketch.beginShape();
sketch.curveVertex(0, lineBaseHeight);
sketch.curveVertex(-10, lineBaseHeight);
sketch.curveVertex(-10, lineBaseHeight);
sketch.curveVertex(0, lineBaseHeight);
for (let i = 1; i < line.spectrum.length - 1; i++) {
const point = line.spectrum[i];
sketch.curveVertex(i * spectrumPointWidth, lineBaseHeight - point);
}
sketch.curveVertex(window.innerWidth, lineBaseHeight);
sketch.curveVertex(window.innerWidth, lineBaseHeight);
sketch.curveVertex(window.innerWidth + 10, lineBaseHeight);
sketch.curveVertex(window.innerWidth + 10, lineBaseHeight);
sketch.endShape();
}
};