图形变换

2017-04-20  本文已影响0人  洛洛kkkkkk
<!DOCTYPE html>
<html>

    <head>
        <meta charset="UTF-8">
        <title></title>
        <style type="text/css">
            #myCanvas {
                border: 2px solid blue;
                /*canvas的宽和高不能在样式表里设置*/
            }
        </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;
        
        //图形变换改变的是整个坐标系
        //平移 translate
//      context.fillRect(0,0,100,100);
//      context.translate(100,100);
//      context.fillStyle = "red";
//      context.fillRect(0,0,100,100);

        //旋转
//      context.fillRect(0,0,100,100);
//      context.rotate(30*deg);
//      context.fillStyle = "red";
//      context.fillRect(0,0,100,100);
        
        //缩放
//      context.save();
//      context.fillRect(0,0,100,100);
//      context.scale(2,2);
//      context.fillStyle = "red";
//      context.fillRect(100,100,100,100);
//      context.restore();
//      context.fillRect(0,200,100,100);



//      context.beginPath();
//      context.arc(300,300,200,0,360*deg,false);
//      context.lineWidth= 5;
//      context.stroke();
//      
//      context.translate(300,300);
//      
//      for(var i=0;i<12;i++){
//          context.rotate(30*deg);
//          context.beginPath();
//          context.moveTo(197,0);
//          context.lineTo(150,0);
//          context.lineCap = "round";
//          context.lineWidth= 10;
//          context.stroke();
//      }


        //贝瑟尔
        
//      context.beginPath();
//      context.moveTo(0,600);
//      context.quadraticCurveTo(300,600,600,0);
//      context.lineWidth = 5;
//      context.stroke();

        context.beginPath();
        context.moveTo(0,600);
        context.bezierCurveTo(0,0,600,600,600,0);
        context.lineWidth = 5;
        context.stroke();
        
    </script>
</html>
上一篇 下一篇

猜你喜欢

热点阅读