HTML5的繪畫支援(五)

來源:互聯網
上載者:User

標籤:style   blog   http   io   ar   os   使用   sp   for   

繪畫:使用路徑-繪製圓形

<html>
<body>
<h2>畫圖入門</h2>
<canvas id="mc" width="600" height="280" style="border:1px solid black"></canvas>
<script>
var canvas=document.getElementById("mc");
var ctx=canvas.getContext("2d");
for( var i=0;i<10;i++)
{
ctx.beginPath();
ctx.arc(i*25,i*25,(i+1)*8,0,Math.PI*2,true);
ctx.closePath();
ctx.fillStyle="rgba(255,0,255,"+(10-i)*0.1+")";
ctx.fill();
}
</script>
</body>
</html>

使用路徑-arcTo示意

<html> <body> <h2>arcTo示意</h2> <canvas id="mc" width="480" height="280" style="border:1px solid black"></canvas> <script>

function createRoundRect(ctx,x1,y1,width,height,radius) { ctx.moveTo(x1+radius,y1); ctx.lineTo(x1+width-radius,y1); ctx.arcTo(x1+width,y1,x1+width,y1+radius,radius); ctx.lineTo(x1+width,y1+height-radius); ctx.arcTo(x1+width,y1+height,x1+width-radius,y1+height,radius); ctx.lineTo(x1+radius,y1+height); ctx.arcTo(x1,y1+height,x1,y1+height-radius,radius); ctx.lineTo(x1,y1+radius);

ctx.arcTo(x1,y1,x1+radius,y1,radius); ctx.closePath(); } var canvas=document.getElementById("mc"); var ctx=canvas.getContext("2d"); ctx.lineWidth=3; createRoundRect(ctx,30,30,200,100,20); ctx.stroke(); </script> </body> </html>

 

HTML5的繪畫支援(五)

聯繫我們

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