From 9a969f541181826b957dbfa268a26982b095c4ee Mon Sep 17 00:00:00 2001 From: Naman Sood Date: Wed, 4 Dec 2024 18:46:55 -0500 Subject: [PATCH] make dots more visible, make them avoid text Signed-off-by: Naman Sood --- js/script.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/js/script.js b/js/script.js index 1581e56..aaa03d0 100644 --- a/js/script.js +++ b/js/script.js @@ -5,8 +5,8 @@ canvas.height = window.innerHeight; const ctx = canvas.getContext('2d'); const FILL_STYLES = { - light: 'rgba(0,0,0,0.05)', - dark: 'rgba(255,255,255,0.15)' + light: 'rgba(0,0,0,0.15)', + dark: 'rgba(255,255,255,0.25)' }; const colorMode = localStorage.getItem('color-mode'); @@ -25,6 +25,10 @@ function isDarkMode() { (document.body.classList.length === 0 && matchMedia('(prefers-color-scheme: dark)').matches); } +function contains(rect, x, y) { + return (rect.left <= x && x <= rect.right) && (rect.top <= y && y <= rect.bottom); +} + function Point() { const r = 8; @@ -38,9 +42,12 @@ function Point() { // moves point to a random location and // resets its progress this.init = function() { + const textbox = document.querySelector('.text-container').getBoundingClientRect(); this.progress = initialProgress; - this.x = Math.random() * canvas.width; - this.y = Math.random() * canvas.height; + do { + this.x = Math.random() * canvas.width; + this.y = Math.random() * canvas.height; + } while(contains(textbox, this.x, this.y)); this.r = 0; this.rng = Math.random(); }