canvas-0trasform.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <canvas id="canvas" style="margin:0 auto;border:1px #ddd solid">
        The current browser does not support Canvas, can replace the browser a try!
    </canvas>

    <script>

        window.onload = function(){
            var canvas = document.getElementById('canvas');

            canvas.width = 1024;
            canvas.height = 768;

            if(canvas.getContext('2d')){
                var context = canvas.getContext('2d');

                context.fillStyle = "red";
                context.strokeStyle = "#058";
                context.lineWidth = 5;

                ////////////////////////
                //a c e
                //b d f
                //0 0 1
                // a d 水平、垂直缩放
                // b c 水平、垂直倾斜
                // e f 水平、垂直位移
                ////////////////////////

                context.save();
                    context.transform(2,0.2,0.3,1.5,30,50);
                    context.transform(2,-0.2,-0.3,1.5,30,50);

                    // setTransform可以使得之前变换的效果全部失效
                    context.setTransform(1,0,0,1,100,100)
                    context.strokeRect(50,50,300,300);
                    context.fillRect(50,50,300,300);
                context.restore();
    

            }else{
                alert('当前游览器不支持Canvas,请更换游览器后再试!');
            }
        }

    </script>
</body>
<script>
    /*
    变换矩阵 trasform
        a c e
        b d f
        0 0 1

        a 水平缩放(1)
        b 水平倾斜(0)
        c 垂直倾斜(0)
        d 垂直缩放(1)
        e 水平位移(0)
        f 垂直位移(0)
        
    */
</script>
原文地址:https://www.cnblogs.com/cynthia-wuqian/p/4978322.html