線條粗細(xì)問題
網(wǎng)頁剛剛刷新時(shí)速度對線條粗細(xì)有用,但是一會(huì)兒粗細(xì)就不會(huì)再隨著速度改變了,找了好久都沒找到錯(cuò)在哪里,代碼在下邊:
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)}
求解????????
2016-01-16
有更新?lastLineWidth 的值嗎? 沒有看到?
2016-01-12
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))