1
0
mirror of https://github.com/Pomax/BezierInfo-2.git synced 2025-08-21 07:51:49 +02:00
Files
BezierInfo-2/docs/chapters/weightcontrol/rational.js
2020-09-19 14:16:00 -07:00

29 lines
735 B
JavaScript

let curve, ratios=[1, 1, 1, 1];
setup() {
curve = Bezier.defaultCubic(this);
setMovable(curve.points);
for (let i=0; i<4; i++) {
// Set up a slider, but in a way that does not tie it to a variable
// that is exposed through `this`, because we want to store its value
// in the "ratios" array we already declared globally.
//
// To make that happen, we tell the slider logic that it should be
// calling the setRatio function instead when the slider moves.
setSlider(`.ratio-${i+1}`, `!ratio-${i+1}`, 1, v => this.setRatio(i,v))
}
}
setRatio(i, v) {
ratios[i] = v;
curve.setRatios(ratios);
redraw();
}
draw() {
clear();
curve.drawSkeleton();
curve.drawCurve();
curve.drawPoints();
}