function setup() {
createCanvas(600, 300);
textSize(18);
curvePointLocationSlider = createSlider(0, 1, 0, 0.1);
curvePointLocationSlider.position(20, 40);
}
function draw() {
background("green");
fill("black");
text(
"Move the slider to change the location of the displayed curve point",
10, 20
);
// Get the required location of curve
curvePointLocationValue = curvePointLocationSlider.value();
let p1 = { x: 50, y: 250 };
let p2 = { x: 140, y: 150 };
let p3 = { x: 400, y: 150 };
let p4 = { x: 350, y: 250 };
// Draw curve using curveVertex()
beginShape();
curveVertex(p1.x, p1.y);
curveVertex(p2.x, p2.y);
curveVertex(p3.x, p3.y);
curveVertex(p4.x, p4.y);
endShape();
// Find the X and Y coordinate using the curvePoint() function
let pointX = curvePoint(p1.x, p2.x, p3.x, p4.x, curvePointLocationValue);
let pointY = curvePoint(p1.y, p2.y, p3.y, p4.y, curvePointLocationValue);
fill("orange");
// Display a circle at that point
circle(pointX, pointY, 10);
}