canvas绘制太极图

效果图:

代码:

<!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>

猜你喜欢

转载自blog.csdn.net/ramosTears123/article/details/88795442
今日推荐