Fixed volume lines
This commit is contained in:
parent
ee60abc62b
commit
7194376bc8
17
src/index.js
17
src/index.js
|
@ -57,7 +57,6 @@ async function main() {
|
||||||
// analyser.getByteTimeDomainData(self.spectrum);
|
// analyser.getByteTimeDomainData(self.spectrum);
|
||||||
|
|
||||||
spectrum.reverse();
|
spectrum.reverse();
|
||||||
|
|
||||||
|
|
||||||
const volume = getRMS(spectrum);
|
const volume = getRMS(spectrum);
|
||||||
const pitch = getPitch(spectrum, volume);
|
const pitch = getPitch(spectrum, volume);
|
||||||
|
@ -93,17 +92,7 @@ async function main() {
|
||||||
sketch.colorMode(sketch.HSL, 255);
|
sketch.colorMode(sketch.HSL, 255);
|
||||||
};
|
};
|
||||||
|
|
||||||
let shouldDraw = 0;
|
|
||||||
|
|
||||||
sketch.draw = () => {
|
sketch.draw = () => {
|
||||||
shouldDraw += 1;
|
|
||||||
if (shouldDraw > 0) {
|
|
||||||
if (shouldDraw > 3) {
|
|
||||||
shouldDraw = -1;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
sketch.background(sketch.color(0, 0, 0));
|
sketch.background(sketch.color(0, 0, 0));
|
||||||
for (let l = 0; l < lines.length; l++) {
|
for (let l = 0; l < lines.length; l++) {
|
||||||
const lineBaseHeight = baseHeight - (l * LINE_MARGIN);
|
const lineBaseHeight = baseHeight - (l * LINE_MARGIN);
|
||||||
|
@ -112,14 +101,16 @@ async function main() {
|
||||||
sketch.stroke(((line.pitch - minPitch) / (maxPitch - minPitch)) * 255);
|
sketch.stroke(((line.pitch - minPitch) / (maxPitch - minPitch)) * 255);
|
||||||
sketch.strokeWeight(1);
|
sketch.strokeWeight(1);
|
||||||
sketch.beginShape();
|
sketch.beginShape();
|
||||||
sketch.curveVertex(0, lineBaseHeight);
|
sketch.curveVertex(-10, lineBaseHeight);
|
||||||
|
sketch.curveVertex(-10, lineBaseHeight);
|
||||||
sketch.curveVertex(0, lineBaseHeight);
|
sketch.curveVertex(0, lineBaseHeight);
|
||||||
for (let i = 1; i < line.spectrum.length - 1; i++) {
|
for (let i = 1; i < line.spectrum.length - 1; i++) {
|
||||||
const point = line.spectrum[i];
|
const point = line.spectrum[i];
|
||||||
sketch.curveVertex(i * spectrumPointWidth, lineBaseHeight - point);
|
sketch.curveVertex(i * spectrumPointWidth, lineBaseHeight - point);
|
||||||
}
|
}
|
||||||
sketch.curveVertex(window.innerWidth, lineBaseHeight);
|
sketch.curveVertex(window.innerWidth, lineBaseHeight);
|
||||||
sketch.curveVertex(window.innerWidth, lineBaseHeight);
|
sketch.curveVertex(window.innerWidth + 10, lineBaseHeight);
|
||||||
|
sketch.curveVertex(window.innerWidth + 10, lineBaseHeight);
|
||||||
sketch.endShape();
|
sketch.endShape();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue