代码实现:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<!-- 1.设置canvas元素 -->
<canvas id="canvas" width="200" height="200"></canvas>
<script>
//2.获取canvas画布
const canvas =document.getElementById("canvas");
//3.getContext()返回一个对象,对象包含绘制图形的方法和属性
const ctx = canvas.getContext("2d");
//arc(x,y,radius,startAngle,endAngle)
ctx.arc(75,75,50,0,Math.PI*2);
ctx.closePath();
ctx.fillStyle="pink";
ctx.fill();
ctx.strokeStyle="#ff3d51"
ctx.lineWidth =10;
ctx.stroke();
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<!-- 1.设置canvas元素 -->
<canvas id="canvas" width="400" height="400"></canvas>
<script>
//2.获取canvas画布
const canvas =document.getElementById("canvas");
//3.getContext()返回一个对象,对象包含绘制图形的方法和属性
const ctx = canvas.getContext("2d");
//第一个圆
//arc(x,y,radius,startAngle,endAngle)
ctx.beginPath();
ctx.arc(200,200,100,0,Math.PI*2);
ctx.closePath();
ctx.fillStyle="red";
ctx.fill();
//第二个圆
ctx.beginPath();
ctx.arc(200,200,50,0,Math.PI*2);
ctx.closePath();
ctx.fillStyle ="gold"
ctx.fill();
</script>
</body>
</html>
实现结果: