From feab5d166d6faffaa171fc8420f85164a954c9c9 Mon Sep 17 00:00:00 2001 From: elijah Date: Thu, 6 Jun 2024 00:40:00 +0200 Subject: [PATCH] add comments and modify randomizer --- assets/loader.js | 52 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/assets/loader.js b/assets/loader.js index 30adefe..57aef6f 100644 --- a/assets/loader.js +++ b/assets/loader.js @@ -1,46 +1,64 @@ -window.addEventListener('load', function() { +// keep the main html clean by loading in ascii art from file +function asciiLoader() { fetch('assets/ascii.txt') .then(response => response.text()) .then(data => { const asciiArtContainer = document.getElementById('ascii-art-container'); asciiArtContainer.innerText = data; initAsciiEffect(data); - }); -}); + }); } +// because different screen sizes require different positioning and font size, we adjust it dynamically function adjustFontSize() { const asciiArtContainer = document.getElementById('ascii-art-container'); const windowWidth = window.innerWidth; const windowHeight = window.innerHeight; - const baseFontSize = Math.min(windowWidth, windowHeight) / 135; + const baseFontSize = Math.min(windowWidth, windowHeight) / 145; asciiArtContainer.style.fontSize = `${baseFontSize}px`; asciiArtContainer.style.top = `${windowHeight / 2}px`; asciiArtContainer.style.left = `${windowWidth / 2}px`; - asciiArtContainer.style.transform = 'translate(-50%, -50%)'; - } -window.addEventListener('resize', adjustFontSize); -window.addEventListener('load', adjustFontSize); + asciiArtContainer.style.transform = 'translate(-50%, -50%)'; } +// if you are wondering why this function exists, +// i wanted to play with js, and it should show that everything will deteriorate eventually +// and nothing is permament, so enjoy it while it lasts. function initAsciiEffect(asciiArt) { const asciiArtContainer = document.getElementById('ascii-art-container'); const chars = asciiArt.split(''); - const updateFrequency = 1; + const updateFrequency = 0; function getRandomIndex() { return Math.floor(Math.random() * chars.length); } function flipBit() { const index = getRandomIndex(); const char = chars[index]; - if (char === '0') { - chars[index] = '1'; - } else if (char === '1') { - chars[index] = '0'; - } else if (char === '@') { + if (char === '@') { chars[index] = '#'; } else if (char === '#') { chars[index] = '@'; + } else if (char === '*') { + chars[index] = '-'; } asciiArtContainer.innerText = chars.join(''); } - setInterval(flipBit, updateFrequency); -} - + setInterval(flipBit, updateFrequency); } +// i require a function that greets beings of unknown heritage +function greetBeingOfUnknownHeritage() { + console.log(` +       ___ +      /イ フ +     | _ _| +     / ミ__xノ +   /     | +    /  ヽ  ノ + │  | | |     + / ̄|  | | |   + | ( ̄ヽ_ヽ_)_)  + \二つ       + + `); + console.log("hello there, have fun"); } +window.addEventListener('resize', adjustFontSize); +window.addEventListener('load', adjustFontSize); +window.addEventListener('load', asciiLoader); +window.addEventListener('load', greetBeingOfUnknownHeritage); +// meow \ No newline at end of file