class Line {
constructor({ color = "#fff", emphasis = 1, start, stop }) {
this._start = { x: start.x, y: start.y };
this._stop = { x: stop.x, y: stop.y };
this.color = color;
this.emphasis = emphasis;
}
length() {
return distance(this._start, this._stop);
}
draw(noiseY) {
c.strokeStyle = this.color;
c.lineWidth = mutable fun ? mutable funLineWidth : viewof lineWidth.value;
c.beginPath();
c.moveTo(this._start.x, this._start.y);
const pointDistance = this.length() / (viewof samples.value + 2);
let lastPoint = { x: this._start.x, y: this._start.y };
for (
let x = this._start.x + pointDistance;
x < this._stop.x - pointDistance;
x += pointDistance
) {
let emphasisX =
1 - Math.abs(convertRange(x, this._start.x, this._stop.x, -1, 1));
const point = {
x,
y:
this._start.y +
noise.noise2d(
x,
this._start.y *
((fun ? mutable funDissonance : viewof dissonance.value) / 100) +
noiseY
) *
this.emphasis *
viewof emphasis.value *
emphasisX
};
const controlPoint = {
x: (lastPoint.x + point.x) / 2,
y: (lastPoint.y + point.y) / 2
};
c.quadraticCurveTo(
lastPoint.x,
lastPoint.y,
controlPoint.x,
controlPoint.y
);
lastPoint = point;
}
const controlPoint = {
x: (lastPoint.x + this._stop.x) / 2,
y: (lastPoint.y + this._stop.y) / 2
};
c.quadraticCurveTo(
controlPoint.x,
controlPoint.y,
this._stop.x,
this._stop.y
);
c.stroke();
}
}