diff --git a/static/js/background_anim.js b/static/js/background_anim.js index 6057c0fe1f64e907a6f7716ed3e00cf77543981a..ff2ef4f785daf48489d28c6d63b8f5b65329bc80 100644 --- a/static/js/background_anim.js +++ b/static/js/background_anim.js @@ -234,6 +234,16 @@ const draw = () => { } }; +const mouseVelocity = () => { + // Work out velocity + mouseVel[0] = mousePos[0] - prevMousePos[0]; + mouseVel[1] = mousePos[1] - prevMousePos[1]; + + // Set previous mouse pos + prevMousePos[0] = mousePos[0]; + prevMousePos[1] = mousePos[1]; +}; + const physics = () => { for (let i = 0; i < dots.length; i++) { let dot = dots[i]; // We have to do it this way since we want the dots to update @@ -321,6 +331,7 @@ const tick = (timeStamp) => { if(deltaTime >= (1 / FPS) * 1000) { zero = timeStamp; draw(); + mouseVelocity(); physics(); } @@ -332,14 +343,6 @@ window.addEventListener("mousemove", (event) => { // Scale clientX and clientY in case the screen size has changed mousePos[0] = (canvas.width / window.innerWidth) * event.clientX; mousePos[1] = (canvas.height / window.innerHeight) * event.clientY; - - // Work out velocity - mouseVel[0] = mousePos[0] - prevMousePos[0]; - mouseVel[1] = mousePos[1] - prevMousePos[1]; - - // Set previous mouse pos - prevMousePos[0] = mousePos[0]; - prevMousePos[1] = mousePos[1]; }); window.addEventListener("resize", () => {