function
setup() {
createCanvas(600, 300);
textSize(20);
maxPointsSlider = createSlider(2, 20, 10, 1);
maxPointsSlider.position(20, 40);
}
function
draw() {
background(
"green"
);
fill(
"black"
);
text(
"Move the slider to change the number of intermediate points"
, 10, 20);
maxPoints = maxPointsSlider.value();
let p1 = { x: 50, y: 250 };
let p2 = { x: 140, y: 150 };
let p3 = { x: 400, y: 150 };
let p4 = { x: 500, y: 250 };
noFill();
bezier(p1.x, p1.y, p2.x, p2.y, p3.x, p3.y, p4.x, p4.y);
for
(let i = 0; i <= maxPoints; i++) {
let step = i / maxPoints;
let pointX = bezierPoint(p1.x, p2.x, p3.x, p4.x, step);
let pointY = bezierPoint(p1.y, p2.y, p3.y, p4.y, step);
fill(
"red"
);
ellipse(pointX, pointY, 8, 8);
}
}