萬盛學電腦網

 萬盛學電腦網 >> 網頁制作 >> Html5 >> html5使用canvas畫空心圓與實心圓

html5使用canvas畫空心圓與實心圓

 <canvas id="canvas" width="500" height="500" style="background-color: yellow;"></canvas>

代碼如下:
var canvas=document.getElementById("canvas");
var cxt=canvas.getContext("2d");
//畫一個空心圓
cxt.beginPath();
cxt.arc(200,200,50,0,360,false);
cxt.lineWidth=5;
cxt.strokeStyle="green";
cxt.stroke();//畫空心圓
cxt.closePath();
//畫一個實心圓
cxt.beginPath();
cxt.arc(200,100,50,0,360,false);
cxt.fillStyle="red";//填充顏色,默認是黑色
cxt.fill();//畫實心圓
cxt.closePath();
//空心和實心的組合
cxt.beginPath();
cxt.arc(300,300,50,0,360,false);
cxt.fillStyle="red";
cxt.fill();
cxt.strokeStyle="green";
cxt.stroke();
cxt.closePath();
copyright © 萬盛學電腦網 all rights reserved