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')
.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