diff options
| author | Collin Williams <96917990+bluedragon1221@users.noreply.github.com> | 2026-05-10 14:46:07 -0500 |
|---|---|---|
| committer | Collin Williams <96917990+bluedragon1221@users.noreply.github.com> | 2026-05-10 14:46:07 -0500 |
| commit | 0063bf9d2b2c416a6317cf45f68847b5720aab49 (patch) | |
| tree | 2c8ab6fd181e481bf9faff65e6a80f4330a5ff54 /stars.js | |
| parent | 85a2a330f729d70dfce1b81dc69ec15436a3d44c (diff) | |
updates and new post: 'Summer of PLT'
Diffstat (limited to 'stars.js')
| -rw-r--r-- | stars.js | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/stars.js b/stars.js new file mode 100644 index 0000000..347d7c0 --- /dev/null +++ b/stars.js @@ -0,0 +1,57 @@ +function animate() { + const bg = document.querySelector("#bg"); + + for (const star of bg.children) { + star.x += star.vx; + star.y += star.vy; + + star.style.left = `${star.x}px`; + star.style.top = `${star.y}px`; + } + + requestAnimationFrame(animate); +} + +document.addEventListener("DOMContentLoaded", () => { + const bg = document.createElement("div"); + bg.setAttribute("id", "bg"); + + const numStars = Math.floor((window.innerWidth * window.innerHeight)/10_000); + for (let i = 0; i < numStars; i++) { + const star = document.createElement("div"); + star.classList.add("star"); + + star.x = Math.random() * window.innerWidth; + star.y = Math.random() * window.innerHeight; + + star.vx = (Math.random() - 0.5) * 0.2; + star.vy = (Math.random() - 0.5) * 0.2; + + star.style.left = `${star.x}px`; + star.style.top = `${star.y}px`; + + bg.appendChild(star); + } + document.body.prepend(bg); + + var styleBlock = document.createElement("style"); + styleBlock.textContent = ` + #bg { + position: fixed; + inset: 0; + pointer-events: none; + } + + .star { + position: absolute; + width: 3px; + height: 3px; + border-radius: 50%; + background: #e6e6e6; + box-shadow: 0 0 4px white; + } + `; + document.head.append(styleBlock); + + requestAnimationFrame(animate); +})
\ No newline at end of file |
