1. 程式人生 > >Canvas縮放和旋轉的組合

Canvas縮放和旋轉的組合

 function drawScreen() {
                context.save();
               context.setTransform(1,0,0,1,0,0);
                var angleInRadians=45*Math.PI/180;
                var x=100;
                var y=100;
                var width=50;
                var height=50;
                context.translate(x +.5*width,y +.5*height);
                context.scale(2,2);
                context.rotate(angleInRadians);
                context.fillStyle="red";
                context.fillRect(-0.5*width,-0.5*height,width,height);

                context.restore();
                context.fillStyle="blue";
                context.fillRect(100,100,50,50);
            }