/*jslint es6 */ /*jslint white:true, for:true */ /*global window, document, console, setInterval, clearInterval, Cookies, fc, $ */ "use strict"; fc.movieGraphics.options = { // default to no glitching glitching:0, // default to no looping looping:0, // default cadence cadence:1000/60, // When we select a line, we're going to scroll through all these characters once before we fall on the right one. alpha:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklnopqrstuvwxyz.-=*" }; // These is the option pool our typewriter will use while working. fc.movieGraphics.mge = undefined; fc.movieGraphics.currentText=""; fc.movieGraphics.currentLineIndex=0; fc.movieGraphics.currentCharIndex=0; fc.movieGraphics.intervalController=[]; fc.movieGraphics.effectsController=[]; fc.movieGraphics.killscreenController=[]; fc.movieGraphics.selectedArray=["1234567890"]; fc.movieGraphics.resetScreen = function(){ fc.movieGraphics.currentText = ""; fc.movieGraphics.currentLineIndex = 0; fc.movieGraphics.currentCharIndex = 0; fc.movieGraphics.currentLine = ""; // fc.movieGraphics.currentLine = fc.movieGraphics.selectedArray[fc.movieGraphics.currentLineIndex]; }; fc.movieGraphics.checkHeight = function(){ let displayAreaHeight = $(fc.movieGraphics.targetElement).innerHeight(); let windowHeight = $(window).innerHeight(); if(displayAreaHeight > windowHeight){ let scrollTarget = displayAreaHeight - windowHeight + 100; window.scrollTo(0, scrollTarget); } }; fc.movieGraphics.displayChar = function(){ /* console.clear(); console.log("displayChar"); console.log("currentLine: "+fc.movieGraphics.selectedArray[fc.movieGraphics.currentLineIndex]); console.log("Line Length: "+fc.movieGraphics.selectedArray[fc.movieGraphics.currentLineIndex].length); console.log("charIndex: "+fc.movieGraphics.currentCharIndex); */ // Ok, get our line from the line array fc.movieGraphics.currentLine = fc.movieGraphics.selectedArray[fc.movieGraphics.currentLineIndex]; // check if it's a zero-length line, if it is or if we're at the end of this line, go to the next line. try{ if(fc.movieGraphics.selectedArray[fc.movieGraphics.currentLineIndex].length === 0 || fc.movieGraphics.currentCharIndex === fc.movieGraphics.selectedArray[fc.movieGraphics.currentLineIndex].length) { fc.movieGraphics.currentLineIndex += 1; fc.movieGraphics.currentCharIndex = 0; fc.movieGraphics.currentLine = fc.movieGraphics.selectedArray[fc.movieGraphics.currentLineIndex]; } } catch(e){ console.log(e); fc.movieGraphics.shutDown(); fc.movieGraphics.resetScreen(); return; } // Check if we're done and shutdown if necessary. if(fc.movieGraphics.currentLineIndex === fc.movieGraphics.selectedArray.length-1 && fc.movieGraphics.currentCharIndex === fc.movieGraphics.currentLine.length-1) { fc.movieGraphics.shutDown(); fc.movieGraphics.resetScreen(); return; } // if the current character is a '<', we're going to find the closing tag and add everything at once // (this prevents pauses while we add html tags and attributes in between tags etc.) try{ if(fc.movieGraphics.currentLine.charAt(fc.movieGraphics.currentCharIndex) === '<'){ let currentLine = fc.movieGraphics.currentLine; let breaker = 0; // Fast-forward until we find the corresponding '> let i; for (i = fc.movieGraphics.currentCharIndex; i") { // Ok, found the corresponding >, we can set our breaker to 1 and go back to displaying normally fc.movieGraphics.currentText += fc.movieGraphics.currentLine.charAt(fc.movieGraphics.currentCharIndex); fc.movieGraphics.currentCharIndex+=1; breaker = 1; } else { // We haven't found the corresponding > so add the next character inside the tag and continue. fc.movieGraphics.currentText += fc.movieGraphics.currentLine.charAt(fc.movieGraphics.currentCharIndex); fc.movieGraphics.currentCharIndex+=1; } if(breaker === 1){ break; } } } else { fc.movieGraphics.currentText += fc.movieGraphics.currentLine.charAt(fc.movieGraphics.currentCharIndex); fc.movieGraphics.currentCharIndex+=1; } } catch(e) { // console.log(e); fc.movieGraphics.shutDown(); fc.movieGraphics.resetScreen(); return; } fc.movieGraphics.mge.innerHTML = fc.movieGraphics.currentText + "_"; }; fc.movieGraphics.shutDown=function() { fc.movieGraphics.intervalController.forEach(function (e) { clearInterval(e); }); fc.movieGraphics.currentCharIndex = 0; fc.movieGraphics.currentLine = ""; }; fc.movieGraphics.effectsControl = function(){ let shadowFlicker = Math.floor(Math.random() * 4); let shadowString = "0px 0px "+shadowFlicker+"px 4px #00ff00"; $('body').css('text-shadow', shadowString); let dieroll = Math.floor(Math.random() * 20); let randomScaleX = 1; let randomScaleY = 1; let scaleString = 'scale(1, 1)'; let randomH_Shift = '0px'; let randomV_Shift = '0px'; if(dieroll > 6 || dieroll < 15){ randomScaleX = String(Math.floor(Math.random()*4)); randomScaleY = String(Math.floor(Math.random()*4)); scaleString = 'scale('+randomScaleX+','+randomScaleY+')'; $("#"+fc.movieGraphics.options.targetElement).css('-webkit-transform', scaleString); } else { $("#"+fc.movieGraphics.options.targetElement).css('-webkit-transform', 'scale(1,1)'); } if(dieroll < 15){ $("#"+fc.movieGraphics.options.targetElement).css('-webkit-filter', 'blur(0px)'); } if(dieroll === 15 || dieroll === 16){ $("#"+fc.movieGraphics.options.targetElement).css('-webkit-filter', 'blur(4px)'); $("#"+fc.movieGraphics.options.targetElement).css('-webkit-transform', 'rotateX(45deg)'); $("#"+fc.movieGraphics.options.targetElement).css('-webkit-transform', 'skew(30deg, 20deg);'); } else { $("#"+fc.movieGraphics.options.targetElement).css('-webkit-filter', 'blur(0px)'); $("#"+fc.movieGraphics.options.targetElement).css('-webkit-transform', 'rotateX(0deg)'); $("#"+fc.movieGraphics.options.targetElement).css('-webkit-transform', 'skew(0deg, 0deg)'); } if(dieroll === 17 || dieroll === 18){ randomH_Shift = String(Math.floor(Math.random()*100))+'px'; randomV_Shift = String(Math.floor(Math.random()*100))+'px'; $("#"+fc.movieGraphics.options.targetElement).css('top', randomV_Shift); $("#"+fc.movieGraphics.options.targetElement).css('left', randomH_Shift); $("#"+fc.movieGraphics.options.targetElement).css('-webkit-filter', 'blur(2px)'); randomScaleX = String(Math.floor(Math.random()*10)); randomScaleY = String(Math.floor(Math.random()*10)); scaleString = 'scale('+randomScaleX+','+randomScaleY+')'; $("#"+fc.movieGraphics.options.targetElement).css('-webkit-transform', scaleString); } else { $("#"+fc.movieGraphics.options.targetElement).css('top', '0px'); $("#"+fc.movieGraphics.options.targetElement).css('left', '0px'); $("#"+fc.movieGraphics.options.targetElement).css('-webkit-filter', 'blur(0px)'); $("#"+fc.movieGraphics.options.targetElement).css('-webkit-transform', 'scale(1,1)'); } if(dieroll === 20){ $("#"+fc.movieGraphics.options.targetElement).css('-webkit-filter', 'blur(4px)'); } else { $("#"+fc.movieGraphics.options.targetElement).css('-webkit-filter', 'blur(0px)'); } }; fc.movieGraphics.startScroller = function(){ fc.movieGraphics.mge = document.getElementById(fc.movieGraphics.options.targetElement); fc.movieGraphics.intervalController.push(setInterval(fc.movieGraphics.displayChar, fc.movieGraphics.options.cadence)); if (fc.movieGraphics.options.glitching === 1) { fc.movieGraphics.effectsController.push(setInterval(fc.movieGraphics.effectsControl, fc.movieGraphics.options.cadence)); } };