zoukankan      html  css  js  c++  java
  • HTML5的绘画支持(六)

    绘画:lineTo示意

    <html> 

    <head>    

    <title></title>

    </head>

    <body>

        <h2>lineTo示意</h2>  

       <canvas id="mc" width="480" height="380" style="border:1px solid black"></canvas>    

    <script>

            function createStar(context, n, dx, dy, size) {    

             context.beginPath();       

          var dig = Math.PI / n * 4;   

              context.moveTo(dx, y + dy);    

             for (var i = 0; i <= n; i++) {   

                  var x = Math.sin(i * dig);   

                  var y = Math.cos(i * dig);       

              context.lineTo(x * size + dx, y * size + dy);       

          }     

            context.closePath();     

        }        

    var canvas = document.getElementById("mc");      

       var ctx = canvas.getContext("2d");   

          //画三角形      

       createStar(ctx, 3, 60, 60, 50);     

        ctx.fillStyle = "#f00";     

        ctx.fill();     

        //画五角星        

    createStar(ctx, 5, 160, 60, 50);  

           ctx.fillStyle = "#00f";   

          ctx.fill();      

       //画七角星        

    createStar(ctx, 7, 260, 60, 50);    

         ctx.fillStyle = "#00f";    

         ctx.fill();   

          //画九角星   

          createStar(ctx, 9, 360, 60, 50);     

        ctx.fillStyle = "#f0f";    

         ctx.fill();

        </script>

    </body>

     </html>

  • 相关阅读:
    多线程系列 线程池ThreadPool
    多线程系列 使用多线程的安全问题
    C#反射Assembly 详细说明
    Assembly(c#中简单说明[转]
    反射调用性能比较
    MFC控件GDI编程
    MFC控件第一讲.DC编程
    MFC原理第六讲.消息传递
    MFC原理第五讲.消息映射.以及如何添加消息
    MFC原理第四讲.动态创建机制
  • 原文地址:https://www.cnblogs.com/yhq361/p/4166191.html
Copyright © 2011-2022 走看看