重叠

2017-04-20  本文已影响0人  洛洛kkkkkk
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <style type="text/css">
            #myCanvas{
                border: 10px solid red;
            }
        </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 yuan (x,y,r,color) {
            this.x=x;
            this.y=y;
            this.r=r;
            this.color = color;
            this.hua = function () {
                context.beginPath();
                context.arc(x,y,r,0,360*deg,false);
                context.fillStyle = color;
                context.fill();
            }
        }
        var kk = new yuan(300,300,100,"red");
        kk.hua();
        //destination-over原图在新图的上面
//      context.globalCompositeOperation = "destination-over";
        //新图覆盖原图,默认值
//      context.globalCompositeOperation = "source-over";
        //destination-in 保留原图重合的部分,其他透明
        //source-in 保留新图重合的部分,其他透明
        //destination-out 保留原图不重合的部分,其他透明
        //source-out 保留新图不重合的部分,其他透明
        //destination-atop 保留原图重合部分和新图未重合部分
        //source-atop 保留新图重合部分和新图未重合部分
        //lighter 重合部分颜色叠加
        //copy 只保留新图
        context.globalCompositeOperation = "lighter";
        var greenOne = new yuan(200,300,100,"green");
        greenOne.hua();
        
        
    </script>
</html>

上一篇 下一篇

猜你喜欢

热点阅读