Skip to content

Commit

Permalink
Updated splash text loop (#68)
Browse files Browse the repository at this point in the history
* Content Update

* README Update

* update splash loop
  • Loading branch information
Derek-Servin authored Aug 27, 2024
1 parent a4ac0f5 commit 25efeb3
Showing 1 changed file with 28 additions and 22 deletions.
50 changes: 28 additions & 22 deletions js/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,46 +16,40 @@
/** Displays splash text under heading. Runs forever.*/
async function splashtext() {
const sayings = [
"We are the Dearborn difference™",
"Hands-on Learning, Real World Impact",
"Robotic googly eye innovators",
"\"Do something worth being here for\"",
"Home of Henry",
"Robotic googly eye innovators",
"Education. Opportunity. Growth.",
"Go Blue!",
"Engineering solutions, not just robots",
"Anderson connector enthusiasts",
"Sometimes the things we build are smart",
"Automation with a human touch",
"Our karts race themselves",
"Go Blue!",
"Engineering solutions, not just robots",
"Creators of the autonomous Desert Bus",
"Robotics isn't a hobby, its a lifestyle",
"Automation with a human touch",
"Where every challenge is an opportunity",
"Proud supporters of open source robotics",
"Hands-on Learning, Real World Impact",
"Education. Opportunity. Growth.",
"We are the Dearborn difference™"
"Proud supporters of open source robotics"
];

let lastRand = 0
let tag = document.getElementById("splash-text")
let index = Math.floor(Math.random() * sayings.length);
let direction = 1; // 1 for forward, -1 for backward
let tag = document.getElementById("splash-text");

// noinspection InfiniteLoopJS
while (true) {
//Cycle rand to avoid the same saying twice
let rand
while (true) {
rand = Math.floor(Math.random() * sayings.length)
if (rand !== lastRand) {
break;
}
}
lastRand = rand


const saying = sayings[rand]
const saying = sayings[index]
let current = "|"

//Type each letter individually
for (const l of saying) {
current = current.slice(0, current.length - 1) + l + '|'
tag.innerText = current
await sleep(22)
await sleep(18) //22
}

//Blink for a bit
Expand All @@ -73,7 +67,7 @@ async function splashtext() {
current = current.slice(0, current.length - 2) + '|'
tag.innerText = current

await sleep(19)
await sleep(13) //19
}

//Blink for a bit
Expand All @@ -86,6 +80,18 @@ async function splashtext() {
await sleep(400)
}

// Move to the next index, either forward or backward
index += direction;

// If we reach the end or the beginning, reverse direction
if (index >= sayings.length) {
index = sayings.length - 2; // Avoid repeating last element
direction = -1; // Reverse direction
} else if (index < 0) {
index = 1; // Avoid repeating first element
direction = 1; // Forward direction
}

} //End while
} //End fn

Expand Down

0 comments on commit 25efeb3

Please sign in to comment.