network-website/assets/loader.js
2024-06-06 00:50:23 +02:00

62 lines
2.5 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 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) / 145;
asciiArtContainer.style.fontSize = `${baseFontSize}px`;
asciiArtContainer.style.top = `${windowHeight / 2}px`;
asciiArtContainer.style.left = `${windowWidth / 2}px`;
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 = 0;
function getRandomIndex() {
return Math.floor(Math.random() * chars.length);
}
function flipBit() {
const index = getRandomIndex();
const char = chars[index];
if (char === '@') {
chars[index] = '#';
} else if (char === '#') {
chars[index] = '@';
} else if (char === '*') {
chars[index] = '-';
} else if (char === '-') {
chars[index] = '*';
}
asciiArtContainer.innerText = chars.join('');
}
setInterval(flipBit, updateFrequency); }
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