代碼
提交代碼
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>慕課網(wǎng)Wiki</title>
<style>
#imooc{
border:1px solid #ccc;
}
</style>
</head>
<body>
<canvas id="imooc">您的瀏覽器不支持 HTML5 canvas 標(biāo)簽</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.bezierCurveTo(260,150, 40,260, 160, 80); //調(diào)用了直接繪制橢圓的函數(shù)
ctx.stroke();
//繪制起點(diǎn)
ctx.beginPath();
ctx.arc(40,40,8,0,2*Math.PI)
ctx.fillStyle= "#888"
ctx.fill()
//繪制控制點(diǎn)1
ctx.beginPath();
ctx.arc(260,150,8,0,2*Math.PI)
ctx.fillStyle= "#888"
ctx.fill()
//繪制控制點(diǎn)2
ctx.beginPath();
ctx.arc(40,260,8,0,2*Math.PI)
ctx.fillStyle= "#888"
ctx.fill()
//繪制終點(diǎn)
ctx.beginPath();
ctx.arc(160, 80,8,0,2*Math.PI)
ctx.fillStyle= "#888"
ctx.fill()
</script>
</body>
</html>
運(yùn)行結(jié)果