From 7866a4dffbe67bc140f4db68063b79657fcbce4e Mon Sep 17 00:00:00 2001 From: Joe Adams Date: Fri, 21 Jun 2019 03:13:36 +0100 Subject: [PATCH] Comments + other janitorial edits --- js/RSVP.js | 176 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 112 insertions(+), 64 deletions(-) diff --git a/js/RSVP.js b/js/RSVP.js index 2c1cd98..9d3929b 100644 --- a/js/RSVP.js +++ b/js/RSVP.js @@ -1,5 +1,6 @@ function sReader_randomTimer() { + // Generates random variables for the CSS animations el = document.querySelectorAll("#sReader_outputText .indicator .i"); for (i=0; i 0) { + // There are trailing symbols to process for (i=0; i= (main.length - lookBehind)) @@ -64,55 +81,58 @@ function sReader_stripPunctuation(_word) main = main.slice(0, -lookBehind); } returnVal = [pre, main, post]; + // Bundle everything together in an array to return return returnVal; } function sReader_calculateOrp(_word, _symbols = false) { - - //// Naive approximation of Spritz's ORP algorithm - //// - //// wordCount -> wordCenter -> ORP - //// (deviation from center) -> deviation with - //// ceil() on center - // - // 1 -> 1.0 -> 1 ( 0.0) -> 0 - // 2 -> 1.5 -> 2 (+0.5) -> 0 - // 3 -> 2.0 -> 2 ( 0.0) -> 0 - // 4 -> 2.5 -> 2 (-0.5) -> -1 - // 5 -> 3.0 -> 2 (-1.0) -> -1 - // 6 -> 3.5 -> 3 (-0.5) -> -1 - // 7 -> 4.0 -> 3 (-1.0) -> -1 - // 8 -> 4.5 -> 3 (-1.5) -> -2 - // 9 -> 5.0 -> 3 (-2.0) -> -2 - // 10 -> 5.5 -> 4 (-1.5) -> -2 - // 11 -> 6.0 -> 4 (-2.0) -> -2 - // 12 -> 6.5 -> 4 (-2.5) -> -3 - // 13 -> 7.0 -> 4 (-3.0) -> -3 - // - //// Punctuation appears to be ignored (prepended/appended - //// without affecting ORP). - //// Using floor() or floats the pattern is confusing as - //// it appears to both ascend and descend in integer - //// steps. Using rounding doesn't help, but using ceil - //// there appears to be a pattern of $ (n-(n%4))/4 $. - //// Switching to German gives us a few longer words, - //// and it appears to hold true for all the examples I - //// ran through. + //// Naive approximation of Spritz's ORP algorithm + //// https://www.spritz.com/faqs + //// + //// wordCount -> wordCenter -> ORP + //// (deviation from center) -> deviation with + //// ceil() on center + // + // 1 -> 1.0 -> 1 ( 0.0) -> 0 + // 2 -> 1.5 -> 2 (+0.5) -> 0 + // 3 -> 2.0 -> 2 ( 0.0) -> 0 + // 4 -> 2.5 -> 2 (-0.5) -> -1 + // 5 -> 3.0 -> 2 (-1.0) -> -1 + // 6 -> 3.5 -> 3 (-0.5) -> -1 + // 7 -> 4.0 -> 3 (-1.0) -> -1 + // 8 -> 4.5 -> 3 (-1.5) -> -2 + // 9 -> 5.0 -> 3 (-2.0) -> -2 + // 10 -> 5.5 -> 4 (-1.5) -> -2 + // 11 -> 6.0 -> 4 (-2.0) -> -2 + // 12 -> 6.5 -> 4 (-2.5) -> -3 + // 13 -> 7.0 -> 4 (-3.0) -> -3 + // + //// Punctuation appears to be ignored (prepended/appended + //// without affecting ORP). + //// Using floor() or floats the pattern is confusing as + //// it appears to both ascend and descend in integer + //// steps. Using rounding doesn't help, but using ceil + //// there appears to be a pattern of $ (n-(n%4))/4 $. + //// Switching to German gives us a few longer words, + //// and it appears to hold true for all the examples I + //// ran through. if (_symbols) { + // If _symbols is true, we're considering all characters + // in the word (including symbols) when calculating ORP strippedWord = ["", _word, ""]; } else { strippedWord = sReader_stripPunctuation(_word); } - wordCount = strippedWord[1].length; - wordCenter = (wordCount+1)/2; - orpBias = -1*(wordCount - wordCount%4)/4; - orp = Math.ceil(wordCenter) + orpBias; - orp += strippedWord[0].length; + wordLength = strippedWord[1].length; // Length of the word + wordCenter = (wordLength+1)/2; // Center of the word + orpBias = -1*(wordLength - wordLength%4)/4; // Offset (see above comment block) + orp = Math.ceil(wordCenter) + orpBias; // Return value + orp += strippedWord[0].length; // Account for prefixing symbols if (debug) { @@ -120,30 +140,42 @@ function sReader_calculateOrp(_word, _symbols = false) console.log("sReader_calculateOrp :: \""+ _word +"\""); console.log("sReader_calculateOrp :: "+ " ".repeat(orp-1) +"^"); } + return orp; - } function sReader_printWord(_word, _symbols = false, _iType = "Solid", _iSym = "^", _iCount = 1, _hideText = false) { + // TODO: @sumptum reduce the insane number of parameters being passed in... + // and/or OOPify this mess indicator = true; + // Redundant variable at the moment orp = sReader_calculateOrp(_word, _symbols); word = [_word.slice(0, orp-1), _word.charAt(orp-1), _word.slice(orp, _word.length)]; + // Splitting up the word for printing with different colours htmlBuffer = ''+ word[0].trim() +''+ ''+ word[1].trim() +''+ ''+ word[2].trim() +''+ - '
' ; + '
' ; if (indicator) { indicatorBuffer = ''+ _iSym +''; + // Each indicator symbol is given it's own class for animation/styling purposes htmlBuffer += ''+ " ".repeat(orp-1) + indicatorBuffer.repeat(_iCount) +''; + // Here the indicator is offset by the ORP value as well, so that it lines up + // underneath the word at the ORP } document.getElementById("sReader_outputText").innerHTML = htmlBuffer; document.getElementById("sReader_outputTextDiv").style.marginLeft = -1*((document.getElementById("sReader_outputText").clientWidth/_word.length)*orp) +"px"; + // Not sure this was necessary, appeared when doing some CSS wrangling + // TODO: @sumptum remove/clean up extra div if unnecessary if (_hideText) { el = document.getElementsByClassName("sReader_text"); + // Hide each part of the text + // TODO: @sumptum maybe this could be used for some interesting flickering transition? + // (if not too distracting) for (i=0; i 0) { + // At first this only applied to words longer than 4 characters, + // but that resulted in words with fewer than 4 characters being + // hard to adjust independently of longer words. + // Left it here in case I change my mind about relative speed + // penalties per character delays += (subStr.length)*speedPenalty; + // Adds a speed penalty per character to slow down longer words } } } -} - -function printHelloWorld() { - setInterval( - function() - { - sReader_printWord("Hello,"); - setTimeout( - function() - { - sReader_printWord("world!"); - }, 1000 - ); - }, 2000 - ); } \ No newline at end of file