HTML5之canvas 3 繪製直線

來源:互聯網
上載者:User

標籤:

Context.moveTo(20,20);

Context.lineTo(20,200);

Context.lineWidth=10;  

Context.lineCap=”round”;

Context.lineJoin=”round”;

Context.stroke();

Context.setLineDash([5,15])

<html>    <head>        <meta charset="UTF-8">        <title>橫線-豎線-斜線</title>        <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />    </head>    <body>        <canvas id="canvas" width="500" height="500"></canvas>        <script type="text/javascript">            var oCanvas = document.getElementById("canvas");            var context = oCanvas.getContext("2d");            context.fillStyle = "#ededed";            context.fillRect(0, 0, 500, 500);            //一直線            //1畫線            context.moveTo(400,20);//移端點            context.lineTo(400,200);//畫線            context.strokeStyle = "red";//線的顏色            //stroke() 方法會實際地繪製出通過 moveTo() 和 lineTo() 方法定義的路徑。預設顏色是黑色            context.stroke();//畫框                        //豎線            context.moveTo(20,20);//移端點            context.lineTo(20,200);//畫線            context.lineWidth = 4;//線寬度            context.lineCap = "round";//帽            context.strokeStyle = "red";//線的顏色            context.stroke();//畫框            //橫線            context.moveTo(20,200);//移端點            context.lineTo(200,200);            context.stroke();            //斜線            context.moveTo(20,200);//移端點            context.lineTo(200,20);            context.setLineDash([10,15]);//(1參)10虛線長度;(2)15這根線和下個線的距離;            context.stroke();                    </script>    </body></html>

 

HTML5之canvas 3 繪製直線

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.