这里给大家分享的是一个学习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();


声明:本站(华域联盟www.cnhackhy.com)所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。