canvas一周一练 -- canvas绘制太极图(6)

运行效果:

<!DOCTYPE html>
<html>
<head>
</head>
<body>
    <canvas id="drawing" width="600" height="600">A drawing of someing!</canvas>
    <script type="text/javascript">
   var drawing = document.getElementById('drawing');
        if(drawing.getContext) {
            //绘制太极图
            var context = drawing.getContext('2d');
            context.fillStyle = 'Lavender';
            context.fillRect(0, 0, 600, 400);
            //画外面的两个大半圆
            context.fillStyle = '#000';
            context.beginPath();
            context.arc(200, 200, 180, 0.5*Math.PI, 1.5*Math.PI, false);
            context.closePath();
            context.fill();
            context.fillStyle = '#fff';
            context.beginPath();
            context.arc(200, 200, 180, 1.5*Math.PI, 0.5*Math.PI, false);
            context.closePath();
            context.fill();
            //画里面的两个小半圆
            context.beginPath();
            context.arc(200, 110, 90, 0.5*Math.PI, 1.5*Math.PI, false);
            context.closePath();
            context.fill();
            context.fillStyle = '#000';
            context.beginPath();
            context.arc(200, 290, 90, 1.5*Math.PI, 0.5*Math.PI, false);
            context.closePath();
            context.fill();
            //画里面的两个小圆
            context.beginPath();
            context.arc(200, 110, 20, 0, 2*Math.PI, false);
            context.closePath();
            context.fill();
            context.fillStyle = '#fff';
            context.beginPath();
            context.arc(200, 290, 20, 0, 2*Math.PI, false);
            context.closePath();
            context.fill();
        }

    </script>
</body>
</html>

 

posted @ 2017-08-15 15:09  张不丢  阅读(466)  评论(0编辑  收藏  举报