HTML5畫布(基礎篇11-10)

來源:互聯網
上載者:User

標籤:style   blog   http   io   color   ar   java   sp   strong   

 1 <script type="text/javascript"> 2     $(function(){ 3         var s = $("#myCanvas")[0]; 4         var canvas = s.getContext("2d"); 5         //畫直線 6         canvas.strokeStyle = "#FF0000"; 7         canvas.moveTo(100,100); 8         canvas.lineTo(300,400); 9         canvas.stroke();10         canvas.beginPath();11         canvas.moveTo(100,100);12         canvas.lineTo(400,300);13         canvas.stroke();14     //2、畫矩形15         var c = s.getContext("2d");16         //填充顏色17         c.fillStyle="blue";18         c.beginPath();19         //方式一(填充)20         c.fillRect(10,10,30,30);21         c.beginPath();22         //方式二(填充)23         c.rect(300,300,100,100);24         c.fill();25         c.beginPath();26         //線條顏色27         c.strokeStyle="yellow";28         c.strokeRect(50,50,30,30);29     //3、畫圓30         c.beginPath();31         //線條寬度32         c.lineWidth = 3;33         //線條顏色34         c.strokeStyle="black";35         // 參數:  x,y,r,開始弧度,結束弧度,順逆時針36         c.arc(200,200,30,0,360*Math.PI/180,false);37         //空心元38         c.stroke();39         //實心圓40         c.fill();41     //4、html5沒有提供畫圓角矩形API 但是通過arcTo方法可以實現這個效果42         c.beginPath();43         c.moveTo(200,200);44         c.lineTo(250,200);45         c.arcTo(300,200,300,250,30);46         c.lineTo(300,300);47         c.stroke();48         49     });50 </script>

對於畫圓角矩形而言:arcTo()的5個參數分別代表 A點的座標 B的座標 以及半徑

HTML5畫布(基礎篇11-10)

聯繫我們

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