代碼
提交代碼
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>慕課網Wiki</title>
<style>
#imooc{
border:1px solid #ccc;
}
</style>
</head>
<body>
<canvas id="imooc">您的瀏覽器不支持 HTML5 canvas 標簽</canvas>
<script>
const canvas = document.getElementById('imooc');
canvas.width=300
canvas.height=300
const ctx = canvas.getContext('2d');
ctx.strokeStyle="#456795";
ctx.lineWidth=8;
ctx.beginPath();
ctx.moveTo(40,40);
ctx.quadraticCurveTo(260,150, 40,260); //調用了直接繪制橢圓的函數
ctx.stroke();
//繪制起點
ctx.beginPath();
ctx.arc(40,40,8,0,2*Math.PI)
ctx.fillStyle= "#888"
ctx.fill()
//繪制控制點
ctx.beginPath();
ctx.arc(260,150,8,0,2*Math.PI)
ctx.fillStyle= "#888"
ctx.fill()
//繪制終點
ctx.beginPath();
ctx.arc(40,260,8,0,2*Math.PI)
ctx.fillStyle= "#888"
ctx.fill()
</script>
</body>
</html>
運行結果