fix: progress fills arc only, matching scale marks on arc
This commit is contained in:
@@ -90,29 +90,22 @@ function draw(cur,max){
|
||||
ctx.clearRect(0,0,W,H);
|
||||
const sx=Ca/640*W,sy=Cb/480*H,sr=Cr/640*W;
|
||||
const gw=Math.max(36,W/18);
|
||||
const ae=d2r(Ae),ex=sx+sr*Math.cos(ae),ey=sy+sr*Math.sin(ae),lx=W*.93;
|
||||
const arcLen=Math.PI*2*sr*((Ae-As)/360),lineLen=lx-ex,totalLen=arcLen+lineLen;
|
||||
const ae=d2r(Ae),ex=sx+sr*Math.cos(ae),ey=sy+sr*Math.sin(ae);
|
||||
const rl=max*.85;
|
||||
|
||||
// background stroke
|
||||
// background: arc + line
|
||||
ctx.beginPath();
|
||||
ctx.arc(sx,sy,sr,d2r(As),d2r(Ae),false);
|
||||
ctx.lineTo(lx,ey);
|
||||
ctx.lineTo(W*.93,ey);
|
||||
ctx.strokeStyle='rgba(255,255,255,.04)';
|
||||
ctx.lineWidth=gw;
|
||||
ctx.stroke();
|
||||
|
||||
// progress stroke
|
||||
// progress: ARC ONLY (0→max RPM fills the 90° arc)
|
||||
const pc=Math.min(cur/max,1);
|
||||
if(pc>.005){
|
||||
const pd=pc*totalLen;
|
||||
ctx.beginPath();
|
||||
if(pd<=arcLen){
|
||||
ctx.arc(sx,sy,sr,d2r(As),d2r(As+(Ae-As)*(pd/arcLen)),false);
|
||||
}else{
|
||||
ctx.arc(sx,sy,sr,d2r(As),d2r(Ae),false);
|
||||
ctx.lineTo(ex+(pd-arcLen)/lineLen*(lx-ex),ey);
|
||||
}
|
||||
ctx.arc(sx,sy,sr,d2r(As),d2r(As+(Ae-As)*pc),false);
|
||||
ctx.strokeStyle=cur>=rl?'rgba(255,50,35,.95)':'rgba(255,255,255,.85)';
|
||||
ctx.lineWidth=gw;
|
||||
ctx.stroke();
|
||||
|
||||
Reference in New Issue
Block a user