网页刚刚刷新时速度对线条粗细有用,但是一会儿粗细就不会再随着速度改变了,找了好久都没找到错在哪里,代码在下边:
var maxLineWidth=20;
var minLineWidth=1;
var maxStrokeV=10;
var minStrokeV=0.1;
function calcLineWidth(t,s){
var v=s/t;
var resultLineWidth
if(v<=minStrokeV)
resultLineWidth=maxLineWidth;
else if(v>=maxStrokeV)
resultLineWidth=minLineWidth;
else
resultLineWidth=maxLineWidth-(v-minStrokeV)/(maxStrokeV-minStrokeV)*(maxLineWidth-minLineWidth)
if(lastLineWidth== -1)
return resultLineWidth;
return lastLineWidth*2/3+ resultLineWidth*1/3;
}
function calcDistance(loc1,loc2){
return Math.sqrt((loc1.x - loc2.x) * (loc1.x - loc2.x) + (loc1.y - loc2.y) * (loc1.y + loc2.y))
}
function windowToCanvas(x,y){
var bbox=canvas.getBoundingClientRect()
return {x:Math.round(x-bbox.left),y: Math.round(y-bbox.top)}
求解????????
有更新 lastLineWidth 的值吗? 没有看到
function calcDistance(loc1,loc2){
return Math.sqrt((loc1.x - loc2.x) * (loc1.x - loc2.x) + (loc1.y - loc2.y) * (loc1.y + loc2.y))
}
------> return Math.sqrt((loc1.x - loc2.x) * (loc1.x - loc2.x) - (loc1.y + loc2.y) * (loc1.y + loc2.y))