虚线可以这样画,把一条线分成红白两半,然后红白交替拼接
var size = 35;
for(var i=0;i<size;i++){
context.beginPath();
if(i % 2 == 0){
context.moveTo(cW * i / size, cH * i / size);
context.lineTo(cW * (i+1) / size, cH * (i+1) / size);
context.stroke();
}
}
var size = 35;
for(var i=0;i<size;i++){
context.beginPath();
if(i % 2 == 0){
context.moveTo(cW * i / size, cH * i / size);
context.lineTo(cW * (i+1) / size, cH * (i+1) / size);
context.stroke();
}
}
2018-03-03
我是这个算法:
ctx.lineWidth = 30 - (curLoc.x - lostLoc.x) + (curLoc.y - lostLoc.y);
大家可以参考一下
ctx.lineWidth = 30 - (curLoc.x - lostLoc.x) + (curLoc.y - lostLoc.y);
大家可以参考一下
2017-10-05
计算线宽的公式(两种写法都可以):
lineWidth=maxLineWidth-(v-minSpeed)*(maxLineWidth-minLineWidth)/(maxSpeed-minSpeed);
lineWidth=minLineWidth+(maxSpeed-v)*(maxLineWidth-minLineWidth)/(maxSpeed-minSpeed);
lineWidth=maxLineWidth-(v-minSpeed)*(maxLineWidth-minLineWidth)/(maxSpeed-minSpeed);
lineWidth=minLineWidth+(maxSpeed-v)*(maxLineWidth-minLineWidth)/(maxSpeed-minSpeed);
2017-08-26
分享一段我自己试出来的不错的效果算法(反比例函数)
if(v<0.1)
newV = 30;
else
newV = Math.ceil( 20/(v+0.9)+10 );
if(v<0.1)
newV = 30;
else
newV = Math.ceil( 20/(v+0.9)+10 );
2017-08-23