html之canvas

來源:互聯網
上載者:User

標籤:c   style   class   blog   code   java   

canvas程式碼片段:

<canvas id="testCanvas" width="400" height="150" style="border:1px solid red;"></canvas><script>var testCanvas= document.getElementById("testCanvas");var ctx = testCanvas.getContext("2d");
//beginPath方法ctx.beginPath(); ctx.moveTo(
10, 10); ctx.lineTo(80, 80); ctx.lineTo(10, 80); ctx.lineWidth=4; ctx.strokeStyle = "blue"; ctx.stroke(); //可通過注釋或取消注釋下面的beginPath來看看實際效果 //ctx.beginPath(); ctx.moveTo(120, 20); ctx.lineTo(120, 50); ctx.lineTo(180, 50); ctx.lineWidth=2; ctx.strokeStyle = "red"; ctx.stroke();
//closePath方法ctx.moveTo(
10, 10); ctx.lineTo(80, 80); ctx.lineTo(10, 80); //可通過注釋或取消注釋下面的beginPath來看看實際效果 //ctx.closePath();</scirpt>

 

1 beginPath:

1.1 起始一條路徑,或重設當前路徑--如果是僅僅一次性的繪製(stroke等繪製方法使用一次)的時候,則該方法有沒有都可以。
1.2 但一般都會繪製很多次,所以,必須加上beginPath方法,好讓前面繪製的一些參數不會影響接下來的圖形繪製

 

2 closePath:

2.1 建立從當前點回到起始點的路徑--所以如果不是繪製封閉圖形,一般不用該方法

 

 

參考:

http://www.w3school.com.cn/tags/html_ref_canvas.asp

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.