You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
2.9 KiB
80 lines
2.9 KiB
5 years ago
|
/*
|
||
5 years ago
|
* text.js
|
||
|
* function for the purpose of my portfolio to animate welcome text
|
||
|
* Author: phga/teord
|
||
|
* Date: 2019-10-23
|
||
|
* Version: 1.0
|
||
|
*/
|
||
5 years ago
|
// set a global var "run" to true before running this function
|
||
5 years ago
|
"use strict";
|
||
5 years ago
|
async function flyingText(canvas) {
|
||
5 years ago
|
canvas.classList.remove("hidden");
|
||
|
|
||
|
while (runTextAnimation) {
|
||
|
// wait till ele is rdy in dom + time between spawns
|
||
|
await shootText(canvas, 4);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
async function shootText(canvas, sec, sta) {
|
||
5 years ago
|
// TODO: move to argument, load from backend
|
||
5 years ago
|
let statements = sta || ["Keyboard-Nerd", "🖤", "Emacs",
|
||
5 years ago
|
"Lives in VI", "GNU/Linux", "Arch Linux",
|
||
|
"Computer Science", "Design",
|
||
|
"Javascript", "C/C++", "Go", "Bash",
|
||
|
"Java", "Python", "QMK", "Vector Graphics",
|
||
|
"Adobe Collection", "OP-1", "Synthesizer",
|
||
|
"6y Work Experience", "Network Security",
|
||
|
"CCNA", "Cisco", "Firewalling", "Project MGMT",
|
||
|
"IT Specialist", "Git", "FreeBSD", "Photography",
|
||
|
"Emacs-Lisp", "Sophos Firewall",
|
||
|
"Microsoft Server", "Appgate", "Palo Alto FW",
|
||
|
"Linux Server", "FreeNAS", "Hardware",
|
||
|
"Arduino", "Electronics", "Soldering",
|
||
|
"Full Stack Networking", "Hotline-Manager",
|
||
|
"Trainer for IT-Specialists", "Matlab/Octave",
|
||
|
"PHP", "CSS", "HTML", "Privacy Advocate",
|
||
|
"Winter is coming!", "😺 Person", "Blender"];
|
||
5 years ago
|
|
||
|
let stCount = statements.length;
|
||
5 years ago
|
let animationTime = sec;
|
||
5 years ago
|
let maxX , maxY, x, y;
|
||
5 years ago
|
// Browser resize
|
||
|
maxX = canvas.offsetWidth / 2;
|
||
|
maxY = canvas.offsetHeight / 2;
|
||
5 years ago
|
|
||
5 years ago
|
let curr = document.createElement("p");
|
||
|
curr.innerHTML = statements[getRand(stCount)];
|
||
|
curr.className = "flying-text";
|
||
|
curr.style.transition = `${animationTime}s ease-in`;
|
||
5 years ago
|
|
||
5 years ago
|
// Get random position + correction to not touch middle to much
|
||
|
x = getRand(maxX * 0.2, maxX);
|
||
|
y = getRand(maxY * 0.45, maxY);
|
||
5 years ago
|
|
||
5 years ago
|
// Random direction and correction to not touch right border
|
||
|
x = (getRand(2) == 1) ? -1*x : 0.3 * x;
|
||
|
y = (getRand(2) == 1) ? -1*y : 0.8 * y;
|
||
5 years ago
|
|
||
5 years ago
|
canvas.appendChild(curr);
|
||
|
await sleep(1000);
|
||
5 years ago
|
|
||
5 years ago
|
// add the stuff that should be animated (transition in class)
|
||
|
curr.style.transform = `translate(${x}px, ${y}px)`;
|
||
|
curr.style.fontSize = `${Math.random() + Math.random() + 1.0}vw`;
|
||
5 years ago
|
|
||
5 years ago
|
// wait to remove it (async)
|
||
|
setTimeout(() => {
|
||
|
curr.remove();
|
||
|
}, animationTime * 1000 + 2000);
|
||
5 years ago
|
}
|
||
|
|
||
|
function getRand(max, min) {
|
||
|
min = min || 0;
|
||
|
return min + Math.floor(Math.random() * (max - min));
|
||
|
}
|
||
|
|
||
|
function sleep(ms) {
|
||
|
return new Promise((nil) => setTimeout(nil, ms));
|
||
|
}
|