代码如下:
<!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画图之画圆形的实例介绍的详细内容。
