html5 canvas路径

HTML5 Canvas 路径

  • 子路径是连接两点的连接。
  • 起点和结束点是连接子路径。
  • 某些预定决定方法是在Create Path:Lineto(),Arcto(),Quadraticto()和Beziercurveto()中使用的
  • withpath()方法启动一个新路径。

HTML5 Canvas 路径语法

context.beginPath();

HTML5 Canvas 路径示例

<!DOCTYPE HTML>

<html>

  <head>

    <style>

      body

{

        margin: 0px;

        padding: 0px;

      }

      #myCanvas

 {

        border: 1px solid #9C9898;

      }

    </style>

    <script>

        window.onload = function ()

 {

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

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

 

            context.beginPath();

            context.moveTo(100, 20);

 

            //line 1

            context.lineTo(200, 160);

 

            //quadratic curve

            context.quadraticCurveTo(230, 200, 250, 120);

 

            //bezier curve

            context.bezierCurveTo(290, -40, 300, 200, 400, 150);

 

            //line 2

            context.lineTo(500, 90);

 

            context.lineWidth = 5;

            context.strokeStyle = "blue";

            context.stroke();

        };

 

    </script>

  </head>

  <body>

    <canvas id="myCanvas" width="578" height="200"></canvas>

  </body>

</html>
日期:2020-04-11 23:04:09 来源:oir作者:oir