zoukankan      html  css  js  c++  java
  • canvas-star6-drawMoon.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 = 800;
                canvas.height = 800;
    
                if(canvas.getContext('2d')){
                    var context = canvas.getContext('2d');
    
                    // context.arc(400,400,300,0.5*Math.PI,1.5*Math.PI,true);
                    // context.moveTo(400,100);
                    // context.arcTo(1200,400,400,700,(400-100)*dis(400,100,1200,400)/(1200-400))
                    // context.stroke();
    
                    fillMoon(context,2,400,400,300,0)
    
                }else{
                    alert('当前游览器不支持Canvas,请更换游览器后再试!');
                }
            }
    
            function dis(x1,y1,x2,y2){
                return Math.sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2))
            }
    
    
            // 优化
            // x,y位置 r半径
            function fillMoon(cxt,d,x,y,R,rot,fillColor){
                cxt.save();
                    cxt.translate(x,y);
                    cxt.rotate(rot*Math.PI/180);
                    cxt.scale(R,R);
                    pathMoon(cxt,d);
                    cxt.fillStyle = fillColor || "#fb5";
                    cxt.fill();
                cxt.restore();
            }
    
            function pathMoon(cxt,d){
                cxt.beginPath();
                    cxt.arc(0,0,1,0.5*Math.PI,1.5*Math.PI,true);
                    moveTo(0,-1);
                    cxt.arcTo(d,0,0,1,dis(0,-1,d,0)/d);
                    // 或者使用贝塞尔二次曲线
                    // cxt.quadraticCurveTo(1.2,0,0,1)
                cxt.closePath();
            }
    
            function dis(x1,y1,x2,y2){
                return Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))
            }
        </script>
    </body>
    </html>
  • 相关阅读:
    app.config应该放哪?
    Connection 和Dispose的学习日志
    简单的sqlhelper的学习日志
    EF 事务(非分布式事务)
    Angularjs 地址联动2.1.1
    C# 如何物理删除有主外键约束的记录?存储过程实现
    C# 枚举基本用法及扩展方法
    JS 去除重复元素的方法
    MVC4程序运行报错
    ASP.NET MVC4 & Entity Framework 6.0 IIS 部署出错解决方案
  • 原文地址:https://www.cnblogs.com/cynthia-wuqian/p/4981617.html
Copyright © 2011-2022 走看看