saw*_*awa 6 javascript html5 canvas
我正在尝试实现这个问题中提到的那种wating动画,特别是看起来像这样的东西:

但我不想使用图形文件,我试图纯粹在html5 canvas和javascript中实现它.另外,我想要一个圆形的黑色背景而不是正方形的背景.作为第一步,我尝试绘制一个静态帧(没有任何移动/旋转)并执行此操作:
<html>
<head><script>
window.onload = function(){
var c=document.getElementById("waiting").getContext("2d");
c.lineCap="round";
c.fillStyle="#353535";
c.translate(100,100);
function slit(p){
shade = 256*p;
th = 2*Math.PI*p;
cos = Math.cos(th);
sin = Math.sin(th);
c.strokeStyle = '#'+((shade<<16)+(shade<<8)+shade).toString(16);
c.moveTo(55*cos, 55*sin);
c.lineTo(84*cos, 84*sin);
c.stroke();
c.closePath();
}
c.lineWidth=0;
c.arc(0,0,100,0,Math.PI*2);
c.fill();
c.lineWidth=7;
for(var i = 0;i<1;i+=0.05){slit(i);}
}
</script></head>
<body><canvas id="waiting" width=200 height=200></canvas></body>
</html>
Run Code Online (Sandbox Code Playgroud)
我得到的结果是:

问题在于,lineCap="round"所有"狭缝" lineWidth=0都无法正常工作,并且该属性不适用于圆的边缘.我究竟做错了什么?我用Chrome 16.0.912.63和Firefox 10.0检查了它,得到了类似的结果.
对于下一步,我将让我在上面创建的部分函数进行交互
window.animationFrames = (function(callback){
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function(callback){window.setTimeout(callback, 1000 / 60);};
})();
Run Code Online (Sandbox Code Playgroud)
但就目前而言,我需要先解决这个问题.
这里有一点混乱。
零不是可接受的线宽值。规范规定,如果你说lineWidth = 0这将是一个空操作。
此外,你没有lineWidth在那里使用,因为你没有抚摸。fill()不考虑线宽。
至于其他问题,您只需致电即可beginPath!看这里:
只需添加beginPath调用,您就会通过代码得到以下结果:

您所做的错误是在每个新的stroke(). 您需要致电beginPath打开一个新零件,以便stroke仅适用于最后一个零件,而不适用于迄今为止制作的所有零件。