代碼
提交代碼
<!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.beginPath();
ctx.moveTo(40,40);
ctx.arcTo(260,40, 260,200, 60); //調(diào)用了繪制圓的函數(shù)
ctx.strokeStyle = "#456795";
ctx.lineWidth = 4;
ctx.stroke();
// ==============一下內(nèi)容為復(fù)制內(nèi)容=================
// 繪制切線
ctx.beginPath()
ctx.strokeStyle="#ccc";
ctx.lineWidth=1;
ctx.moveTo(40,40);
ctx.lineTo(260,40);
ctx.lineTo(260,260);
ctx.stroke();
//繪制P點(diǎn)
ctx.beginPath();
ctx.arc(260,40,4,0, 2*Math.PI)
ctx.fillStyle = "#000"
ctx.fill()
//繪制A點(diǎn)
ctx.beginPath();
ctx.arc(40,40,4,0, 2*Math.PI)
ctx.fillStyle = "#000"
ctx.fill()
//繪制B點(diǎn)
ctx.beginPath();
ctx.arc(260,200,4,0, 2*Math.PI)
ctx.fillStyle = "#000"
ctx.fill()
//繪制切點(diǎn)
ctx.beginPath();
ctx.arc(200,40,4,0, 2*Math.PI)
ctx.fillStyle = "yellow"
ctx.fill()
//繪制切點(diǎn)
ctx.beginPath();
ctx.arc(260,100,4,0, 2*Math.PI)
ctx.fillStyle = "yellow"
ctx.fill()
//繪制圓心 O 點(diǎn)
ctx.beginPath();
ctx.arc(200,100,4,0, 2*Math.PI)
ctx.fillStyle = "blue"
ctx.fill()
//繪制輔助圓
ctx.beginPath();
ctx.lineWidth = 1;
ctx.strokeStyle="#ccc"
ctx.arc(200,100,60,0, 2*Math.PI)
ctx.stroke()
</script>
</body>
</html>
運(yùn)行結(jié)果