美文网首页
圆周运动

圆周运动

作者: 洛洛kkkkkk | 来源:发表于2017-04-20 19:29 被阅读0次
<!DOCTYPE html>
<html>

    <head>
        <meta charset="UTF-8">
        <title></title>
        <style type="text/css">
            #myCanvas {
                border: 10px solid cyan;
                background-color: cyan;
            }
        </style>
    </head>

    <body>
        <canvas id="myCanvas" width="600" height="600"></canvas>
    </body>
    <script type="text/javascript">
        var myCanvas = document.getElementById("myCanvas");
        var context = myCanvas.getContext("2d");
        var deg = Math.PI/180;
        
        function draw (x,y,color) {
            context.beginPath();
            context.fillStyle = color;
            context.arc(x,y,30,0,360*deg,false);
            context.fill()
        }
        context.translate(300,300);
        setInterval(function () {
            context.clearRect(-300,-300,600,600);
            context.rotate(3*deg);
            draw(150,150,"black");
            draw(-150,-150,"white");
        },20)
        
        
        
    </script>

</html>

相关文章

网友评论

      本文标题:圆周运动

      本文链接:https://www.haomeiwen.com/subject/jtalzttx.html