zoukankan      html  css  js  c++  java
  • canvas-7globleCompositeOperation2.html

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
    </head>
    <style>
        #buttons{width: 1200px;margin: 10px auto;clear:both;}
        #buttons a{font-size: 18px;display: block;float:left;margin-right: 14px;}
    </style>
    <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>
    
        <div id="buttons">
            <a href="">source-over</a>
            <a href="">source-atop</a>
            <a href="">source-in</a>
            <a href="">source-out</a>
            <a href="">destination-over</a>
            <a href="">destination-atop</a>
            <a href="">destination-in</a>
            <a href="">destination-out</a>
            <a href="">lighter</a>
            <a href="">copy</a>
            <a href="">xor</a>
        </div>
    
        <script>
    
            window.onload = function(){
                draw("source-over");
    
                var buttons = document.getElementById("buttons").getElementsByTagName("a");
                for(var i=0;i<buttons.length;i++){
                    buttons[i].onclick = function(){
                        draw(this.text);
                        return false;
                    }
                }
            }
    
            function draw(compositeStyle){
                var canvas = document.getElementById('canvas');
    
                canvas.width = 1024;
                canvas.height = 768;
    
                if(canvas.getContext('2d')){
                    var context = canvas.getContext('2d');
    
                    context.clearRect(0,0,canvas.width,canvas.height);
    
                    // draw title
                    context.font = "bold 40 Arial";
                    context.textAlign = "center";
                    context.textBaseline = "#058";
                    context.fillStyle = "#058";
                    context.fillText("globalCompositeOperation =" + compositeStyle,canvas.width/2,60);
    
                    // draw a rect
                    context.fillStyle = "blue";
                    context.fillRect(300,150,500,500);
    
                    // draw a triangle
                    context.globalCompositeOperation = compositeStyle;
                    context.fillStyle = "red";
                    context.beginPath();
                        context.moveTo(700,250);
                        context.lineTo(1000,750);
                        context.lineTo(400,750);
                    context.closePath();
                    context.fill();
    
                }else{
                    alert('当前游览器不支持Canvas,请更换游览器后再试!');
                };
            }
    
        </script>
    </body>
    <script>
        /*global
    
            globalAlpha
    
            globalCompositeOperation  = "source-over"(default)
                                        sourse-atop
                                        sourse-in
                                        sourse-out
    
                                        destination-over  //前面绘制的覆盖了后面绘制的图形
                                        destination-atop
                                        destination-in
                                        destination-out
    
                                        lighter
                                        copy
                                        xor
                    
        */
    </script>
    </html>
  • 相关阅读:
    根据IP头格式 写sniff
    双零碎安设Linux之后找不到Windows分区
    Oracle的共享封锁 独有封锁和共享更新封锁 (3)
    设置配备部署Windows与Linux平台的DATA GURAD (1)
    GTick 桌面节拍器
    在文本终端怎样查看上一屏内容(终端回滚快捷键)
    肃清Cache影响手动逼迫革新Buffer Cache
    Oracle数据库无法加载_OraMTS_的处理赏罚设置装备安置
    Linux操纵琐细下确立DBCA报错的料理要领
    设置Windows与Linux平台的DATA GURAD (2)
  • 原文地址:https://www.cnblogs.com/cynthia-wuqian/p/4988528.html
Copyright © 2011-2022 走看看