效果图:
代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
canvas{
border: 1px solid #000;
margin:100px 400px;
border-radius:200px;
background-image:linear-gradient(90deg,black 50%,white 50%);
}
</style>
</head>
<body>
<canvas width="400" height="400"></canvas>
<script>
var mcanvas=document.getElementsByTagName("canvas")[0];
var ctx=mcanvas.getContext("2d");
ctx.fillStyle="#000";
ctx.arc(200,100,100,0,2*Math.PI);
ctx.fill();
ctx.beginPath();
ctx.fillStyle="#fff";
ctx.arc(200,100,30,0,2*Math.PI);
ctx.fill();
ctx.beginPath();
ctx.fillStyle="#fff";
ctx.arc(200,300,100,0,2*Math.PI);
ctx.fill();
ctx.beginPath();
ctx.fillStyle="#000";
ctx.arc(200,300,30,0,2*Math.PI);
ctx.fill();
</script>
</body>
</html>