shimmerer = async () => {
let object = 0,
replacement = 1;
let indexOfObjectLetter = randInt(letters[object].length);
let objectLetter = letters[object].substr(indexOfObjectLetter, 1);
if (mutable rindex == 0) shuffle(shuffledArray);
mutable rindex = ++mutable rindex % supplyArray.length;
let wordIndex = shuffledArray[mutable rindex];
let shimmeringWord = stripTags(shimmeringArray[wordIndex]);
if (mutable surface && shimmeringWord === supplyArray[wordIndex]) return;
let r = new RegExp(objectLetter, "g");
let a = Array.from(shimmeringWord.matchAll(r));
if (a.length < 1) return;
let indexOfLetterToReplace, modelLetter;
while (a.length > 0) {
let indexOfMatch = randInt(a.length);
indexOfLetterToReplace = a[indexOfMatch].index;
a.splice(indexOfMatch, 1);
// get currently displayed letter
let letterInWord = shimmeringWord.substr(indexOfLetterToReplace, 1);
// get the corresponding letter in the supply text (its 'model')
modelLetter = supplyArray[wordIndex].substr(indexOfLetterToReplace, 1);
if (mutable surface) {
// do nothing if surfacing and the letter is also a modelLetter
// and there are no other choices
if (letterInWord === modelLetter && a.length == 0) return;
// otherwise try other matches by continuing
} else {
// if shimmering always do something with the letters
// by leaving the while loop
a.length = 0;
}
}
// get the sublitteral pair for the letter we are proposing to replace
let replacementLetter = letters[replacement].substr(indexOfObjectLetter, 1);
shimmeringWord = shimmeringWord.replace(
shimmeringWord.substr(indexOfLetterToReplace, 1),
replacementLetter
);
// add styling to the letter (in different circumstances, including debugging)
if (config.debug) {
let makeChange = mutable surface
? replacementLetter === modelLetter
: replacementLetter !== modelLetter;
if (makeChange)
shimmeringWord = highlight(shimmeringWord, indexOfLetterToReplace);
}
shimmeringArray[wordIndex] = shimmeringWord;
// mutable shimmeringText is referenced by the main display or display cell
mutable shimmeringText = addBackLineEndings(shimmeringArray);
}