您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

html5中关于canvas画图之画圆形的实例介绍

2026/1/7 16:01:16发布26次查看
利用canvas中的arc可以绘制圆形图案。函数原型为:context.arc(x,y,半径,开始角度,结束角度,是否逆时针旋转);所以可以通过修改开始角度和结束角度来绘制弧线。
代码如下:
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>html5圆形</title> <script type="text/javascript"> window.addeventlistener("load",function(){ //canvas的2d上下文 var ctx=document.getelementbyid("canvas").getcontext("2d"); //圆1 ctx.beginpath(); ctx.arc(150,45,35,0,math.pi*2,false); ctx.fillstyle="rgba(192,80,77,0.7)";//半透明的红色 ctx.fill(); ctx.strokestyle="rgba(192,80,77,1)";//红色 ctx.stroke(); //圆2 ctx.beginpath(); ctx.arc(125,95,35,0,math.pi*2,false); ctx.fillstyle="rgba(155,187,89,0.7)";//半透明绿色 ctx.fill(); ctx.strokestyle="rgba(155,187,89,1)";//绿色 ctx.stroke(); //圆3 ctx.beginpath(); ctx.arc(175,95,35,math.pi*2,false); ctx.fillstyle="rgba(128,100,162,0.7)";//半透明的紫色 ctx.fill(); ctx.strokestyle="rgba(128,100,132,1)";//紫色 ctx.stroke(); }); </script> </head> <body> <canvas id="canvas" width="600" height="600"></canvas> </body> </html>
上图是绘制的三个圆形相互折腾的,另外可以直接修改那个开始角度和结束弧度来画弧线。
以上就是html5中关于canvas画图之画圆形的实例介绍的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product