$ git clone https://ion.nu/git/pool
commit cbffebff523c48333f2b014655735adea45086a7
Author: Alicia <...>
Date: Fri Jun 29 23:11:06 2018 +0200
Cue strength indication through semitransparency.
diff --git a/web/pool.js b/web/pool.js
index ff9e26b..ba6e877 100644
--- a/web/pool.js
+++ b/web/pool.js
@@ -141,7 +141,11 @@ function init()
}
if(cue)
{
- ctx.strokeStyle='#ffffff';
+ var vx=((cueball.x+cueball.w/2)*scale-(cueX-offsetX))/scale/5;
+ var vy=((cueball.y+cueball.h/2)*scale-(cueY-offsetY))/scale/5;
+ var speed=Math.sqrt(vx**2+vy**2);
+ if(speed>50){speed=50;}
+ ctx.strokeStyle='rgba(100%,100%,100%,'+(25+speed*1.5)+'%)';
ctx.lineWidth=10*scale;
ctx.lineCap='round';
ctx.beginPath();
@@ -214,16 +218,12 @@ function init()
if(!cue){return;}
cueball.vx=((cueball.x+cueball.w/2)*scale-(x-offsetX))/scale/5;
cueball.vy=((cueball.y+cueball.h/2)*scale-(y-offsetY))/scale/5;
+ var speed=Math.sqrt(cueball.vx**2+cueball.vy**2);
// Sanitize speed
- if(Math.abs(cueball.vx)>38)
+ if(speed>50)
{
- cueball.vy*=38/Math.abs(cueball.vx);
- cueball.vx*=38/Math.abs(cueball.vx);
- }
- if(Math.abs(cueball.vy)>38)
- {
- cueball.vx*=38/Math.abs(cueball.vy);
- cueball.vy*=38/Math.abs(cueball.vy);
+ cueball.vy*=50/speed;
+ cueball.vx*=50/speed;
}
net_cue(cueball);
cue=false;