mirror of
https://github.com/captbaritone/webamp.git
synced 2026-07-20 16:49:52 +00:00
Get all y values in one go
This commit is contained in:
parent
3b7f2d51ac
commit
94476eedc4
2 changed files with 9 additions and 3 deletions
|
|
@ -89,12 +89,12 @@ class EqGraph extends React.Component {
|
|||
ys.push(percentToRange(percent, min, max));
|
||||
});
|
||||
|
||||
const getY = spline(xs, ys);
|
||||
const allYs = spline(xs, ys);
|
||||
|
||||
const maxX = xs[xs.length - 1];
|
||||
let lastY = ys[0];
|
||||
for (let x = 0; x <= maxX; x++) {
|
||||
const y = clamp(Math.round(getY(x)), 0, GRAPH_HEIGHT - 1);
|
||||
const y = clamp(Math.round(allYs[x]), 0, GRAPH_HEIGHT - 1);
|
||||
const yTop = Math.min(y, lastY);
|
||||
const height = 1 + Math.abs(lastY - y);
|
||||
this.canvasCtx.fillRect(paddingLeft + x, yTop, 1, height);
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ export default function spline(xs, ys) {
|
|||
return 0;
|
||||
});
|
||||
ks = getNaturalKs(xs, ys, ks);
|
||||
return x => {
|
||||
const getY = x => {
|
||||
let i = 1;
|
||||
while (xs[i] < x) i++;
|
||||
const t = (x - xs[i - 1]) / (xs[i] - xs[i - 1]);
|
||||
|
|
@ -15,6 +15,12 @@ export default function spline(xs, ys) {
|
|||
(1 - t) * ys[i - 1] + t * ys[i] + t * (1 - t) * (a * (1 - t) + b * t);
|
||||
return q;
|
||||
};
|
||||
const maxX = xs[xs.length - 1];
|
||||
const allYs = [];
|
||||
for (let i = 0; i <= maxX; i++) {
|
||||
allYs.push(getY(i));
|
||||
}
|
||||
return allYs;
|
||||
}
|
||||
|
||||
function getNaturalKs(xs, ys, ks) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue