diff --git a/public/js/background_anim.js b/public/js/background_anim.js index 2d03cf17d3ab43358b74784a46c6568e510e1311..2ad7427be65c32ee5d904eee892c1e02be165b52 100644 --- a/public/js/background_anim.js +++ b/public/js/background_anim.js @@ -251,16 +251,26 @@ window.addEventListener("mousemove", (event) => { }); window.addEventListener("resize", () => { + // Width before resize let oldWidth = canvas.width; + // Height before resize let oldHeight = canvas.height; + + // Set canvas size and display parameters setDisplayParameters(); + + // Calculate old to new width ratio let widthRatio = canvas.width / oldWidth; + // Calculate old to new height ratio let heightRatio = canvas.height / oldHeight; - // Loop all dots + + // Loop through all dots for (let i = 0; i < dots.length; i++) { let dot = dots[i]; + // Reset radius of dots dot.radius = randInt(RADIUS_MIN, RADIUS_MAX); + // Reset dots positions outside new window if the window has gotten smaller dot.x = dot.x * widthRatio; dot.y = dot.y * heightRatio;