Paradox




The beating heart.
beatingHeart = {
  await Promises.tick(2000);

    let fullCycles = 0;
    let currentLines = 0;
    let theseLines = poemLines;

    while (true) {
        let cursor = "_";

        let main = document.getElementById("display");
        // let currentLines = 0;
    
        if (fullCycles > 0) theseLines = fisherYatesShuffle(poemLines);
    
        for (let i = 0; i < theseLines.length; i++) {
          if (currentLines <= 9) {
            // counts the number of lines on display.
            currentLines += 1;
          } else {
            // once t lines have been shown,
            // we remove the last one.
            main.removeChild(document.getElementById("display").lastChild);
          }
    
          let sentenceOut = theseLines[i];
    
          // Create div for the new line.
          let newLine = document.createElement("div");
    
          // Add class and ID for the new line.
          newLine.classList.add("line");
          newLine.setAttribute("id", `line${i}`);
    
          // Add the currently empty line to the main div element.
          // main.append(newLine);
          main.prepend(newLine);
    
          // Print the current line, letter by letter.
          for (let a = 0; a < sentenceOut.length; a++) {
            a != sentenceOut.length - 1 ? (cursor = "_") : (cursor = ".");
            newLine.textContent = yield Promises.tick(
              75,
              sentenceOut.slice(0, a) + cursor
            );
          }
          await Promises.tick(1000);
    }

    fullCycles++;
  }
}
A text file must be split. Parsed.
poemLines = {
  let o = await poem.split(".").map((d) => d.trim() + ".");
  o.pop();
  return o;
}
Fisher-Yates Shuffle.
fisherYatesShuffle = (arr) => {
  let i = arr.length;
  while (--i > 0) {
    let randIndex = Math.floor(Math.random() * (i + 1));
    [arr[randIndex], arr[i]] = [arr[i], arr[randIndex]];
  }
  return arr;
}
A text file must be loaded.
poem = await FileAttachment("paradox.txt").text()