问答详情
源自:3-2 运笔速度对笔画的影响.mp4

线条粗细问题

网页刚刚刷新时速度对线条粗细有用,但是一会儿粗细就不会再随着速度改变了,找了好久都没找到错在哪里,代码在下边:

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)}

求解????????

提问者:qq_獨鬺_0 2016-01-12 11:15

个回答

  • fengzi
    2016-01-16 22:11:37

    有更新 lastLineWidth 的值吗? 没有看到 

  • qq_科_1
    2016-01-12 12:38:06

    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))