add comments and modify randomizer

This commit is contained in:
elijah 2024-06-06 00:40:00 +02:00
parent 6d2425992a
commit feab5d166d

View File

@ -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') fetch('assets/ascii.txt')
.then(response => response.text()) .then(response => response.text())
.then(data => { .then(data => {
const asciiArtContainer = document.getElementById('ascii-art-container'); const asciiArtContainer = document.getElementById('ascii-art-container');
asciiArtContainer.innerText = data; asciiArtContainer.innerText = data;
initAsciiEffect(data); initAsciiEffect(data);
}); }); }
}); // because different screen sizes require different positioning and font size, we adjust it dynamically
function adjustFontSize() { function adjustFontSize() {
const asciiArtContainer = document.getElementById('ascii-art-container'); const asciiArtContainer = document.getElementById('ascii-art-container');
const windowWidth = window.innerWidth; const windowWidth = window.innerWidth;
const windowHeight = window.innerHeight; 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.fontSize = `${baseFontSize}px`;
asciiArtContainer.style.top = `${windowHeight / 2}px`; asciiArtContainer.style.top = `${windowHeight / 2}px`;
asciiArtContainer.style.left = `${windowWidth / 2}px`; asciiArtContainer.style.left = `${windowWidth / 2}px`;
asciiArtContainer.style.transform = 'translate(-50%, -50%)'; asciiArtContainer.style.transform = 'translate(-50%, -50%)'; }
} // if you are wondering why this function exists,
window.addEventListener('resize', adjustFontSize); // i wanted to play with js, and it should show that everything will deteriorate eventually
window.addEventListener('load', adjustFontSize); // and nothing is permament, so enjoy it while it lasts.
function initAsciiEffect(asciiArt) { function initAsciiEffect(asciiArt) {
const asciiArtContainer = document.getElementById('ascii-art-container'); const asciiArtContainer = document.getElementById('ascii-art-container');
const chars = asciiArt.split(''); const chars = asciiArt.split('');
const updateFrequency = 1; const updateFrequency = 0;
function getRandomIndex() { function getRandomIndex() {
return Math.floor(Math.random() * chars.length); return Math.floor(Math.random() * chars.length);
} }
function flipBit() { function flipBit() {
const index = getRandomIndex(); const index = getRandomIndex();
const char = chars[index]; const char = chars[index];
if (char === '0') { if (char === '@') {
chars[index] = '1';
} else if (char === '1') {
chars[index] = '0';
} else if (char === '@') {
chars[index] = '#'; chars[index] = '#';
} else if (char === '#') { } else if (char === '#') {
chars[index] = '@'; chars[index] = '@';
} else if (char === '*') {
chars[index] = '-';
} }
asciiArtContainer.innerText = chars.join(''); 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