欢迎来到DIVCSS5查找CSS资料与学习DIV CSS布局技术!
您的位置:DIVCSS5首页 > DIV+CSS基础 >
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>canvas吃豆鱼</title> </head> <style> body{ text-align:center; } canvas{ background: #efefef; } </style> <body> <h1> 角度转为弧度:<br /> 弧度=2*PI*角度/360=角度*PI/180 </h1> <!--画布的宽和高只能使用属性,不能使用样式--> <canvas id='a1' width="500" height="400"></canvas> </body></html><script> var ctx=a1.getContext('2d');//得到画布上的画笔并设置绘制方式 function openMouse(){ //绘制圆(3/4) ctx.beginPath();//开始一条路径 ctx.arc(250,200,100,45*Math.PI/180,315*Math.PI/180);//圆心为(250,200),半径为100 ctx.lineTo(250,200); ctx.closePath(); ctx.stroke();//勾勒轮廓/描边 ctx.fillStyle='#00ffff'; ctx.fill(); eye(); } //openMouse(); function closeMouse(){ ctx.beginPath();//开始一条路径 ctx.arc(250,200,100,0*Math.PI/180,360*Math.PI/180);//圆心为(250,200),半径为100 ctx.lineTo(250,200); ctx.closePath(); ctx.stroke();//勾勒轮廓/描边 ctx.fillStyle='#00ffff'; ctx.fill(); eye(); } //closeMouse(); //绘制公共部分眼睛 function eye(){ //绘制眼睛 ctx.beginPath(); ctx.arc(250,200-100/2,25,0,2*Math.PI);//眼睛半径为25 ctx.stroke(); ctx.fillStyle='#001900'; ctx.fill(); //绘制眼神光 ctx.beginPath(); ctx.arc(265,140,5,0,2*Math.PI);//眼神光半径为5 ctx.stroke(); ctx.fillStyle='#ffffff'; ctx.fill(); } var isOpen=true;//定义变量isOpen:是否张开 var timer=setInterval(function(){ var ctx=a1.getContext('2d'); ctx.clearRect(0,0,500,400);//清空画布大小 if(isOpen){ closeMouse(); isOpen=false; }else{ openMouse(); isOpen=true; } },500);</script>

如需转载,请注明文章出处和来源网址:http://www.divcss5.com/rumen/r50584.shtml

如对文章有任何疑问请提交到DIV CSS论坛,或有任何网页制作CSS问题立即到CSS论坛发贴求解 或 直接DIVCSS5网页顶部搜索遇到DIVCSS疑问。
CSS教程文章修订日期:2018-08-14 17:37 原创:DIVCSS5
本文www.divcss5.com DIVCSS5版权所有。