我想在二次曲线的每个点上运行一个圆圈,因为我正在制作一个掷圈游戏。这是我的问题的示例代码:
canvas.width = 200;
canvas.height = 200;
ctx = canvas.getContext("2d");
ctx.beginPath();
ctx.moveTo(20,20);
ctx.quadraticCurveTo(20,200,200,200);
ctx.stroke();
ctx.closePath();
ctx.beginPath();
ctx.fillStyle = "orange";
ctx.arc(20,20,20,Math.PI*2,0);
ctx.fill();
function loop(){
//Code to move circle through the quadric curve
//???
//???
ctx.beginPath();
ctx.fillStyle = "orange";
ctx.arc(20,20,20,Math.PI*2,0);
ctx.fill();
requestAnimationFrame(loop);
}
*{
margin: 0;
padding: 0;
}
<canvas id="canvas"></canvas> Run that circle through the curve
我该如何解决这个问题?
对不起我的英语,谢谢你的回答!