HTML5 Canvas arc()函数讲解

为大家介绍曲线的语法。 如果要创建一个圆形,我们可以使用arc()方法。



语法:arc(定义一个中心点,半径,起始角度,结束角度,和绘图方向:顺时针或逆时针)

代码:context.arc(centerX, centerY, radius, startingAngle, endingAngle, antiClockwise);


HTML5 Canvas Arc 说明: HTML5 <wbr>Canvas <wbr>arc()函数讲解 八卦图示例代码: 程序效果如下: HTML5 <wbr>Canvas <wbr>arc()函数讲解 <!DOCTYPE HTML> <html> <head> <meta charset="utf-8" /> <title>无标题文档</title> <!--下面excanvas.js需下载才能在IE下支持canvas--> <!--[if IE]> <script src="http://a.tbcdn.cn/p/fp/2011a/html5.js"></script> <script src="http://api.html5media.info/1.1.4/html5media.min.js"></script> <script src="excanvas.js"></script> <![endif]--> <script type="text/javascript"> window.onload = function(){ var ctx = document.getElementByIdx_x_x_x("pic").getContext('2d'); //绘制白色半圆的代码如下: ctx.beginPath(); ctx.arc(200,200,80,1.5*Math.PI,Math.PI/2,false); ctx.fillStyle="white"; ctx.closePath(); ctx.fill(); //绘制黑色半圆的代码如下: ctx.beginPath(); ctx.arc(200,200,80,Math.PI/2,1.5*Math.PI,false); ctx.fillStyle="black"; ctx.closePath(); ctx.fill(); //绘制黑色小圆 ctx.beginPath(); ctx.arc(200,240,40,0,Math.PI*2,true); ctx.fillStyle="black"; ctx.closePath(); ctx.fill(); //绘制白色小圆 ctx.beginPath(); ctx.arc(200,160,40,0,Math.PI*2,true); ctx.fillStyle="white"; ctx.closePath(); ctx.fill(); //绘制白色小圆心 ctx.beginPath(); ctx.arc(200,160,5,0,Math.PI*2,true); ctx.fillStyle="black"; ctx.closePath(); ctx.fill(); //绘制黑色小圆心 ctx.beginPath(); ctx.arc(200,240,5,0,Math.PI*2,true); ctx.fillStyle="white"; ctx.closePath(); ctx.fill(); //绘制文字代码如下: ctx.save(); ctx.fillStyle="black"; ctx.globalAlpha="0.4"; ctx.textAlign="center"; ctx.font="32px Arial"; ctx.shadowColor="rgba(0,0,0,0.4)"; ctx.shadowOffsetX=15; ctx.shadowOffsetY=-10; ctx.shadowBlur=2; ctx.fillText('Hello Canavs',200,100);//IE不支持 ctx.restore(); } </script> </head> <body> <canvas id="pic" width="400" height="400" style="border:1px solid; background:#E1E1FF;"></canvas> </body> </html>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值