var started = false; var showControls = false; var colorWords = ["red", "orange", "yellow", "green", "blue", "purple", "white"]; var hypnoWords = ["sleep", "relax", "fall", "deeper", "trance"]; var colors = ["red", "orange", "yellow", "green", "blue", "purple", "white"]; var wordEl = document.getElementById("word"); function randomChoice(a) { return a[Math.floor(Math.random()*a.length)]; } var hypnoFrequency = 0; var hypnoIncrements = 10; function changeWord() { var wordList = (Math.random()*hypnoIncrements < hypnoFrequency) ? hypnoWords : colorWords; var newWord; do { newWord = randomChoice(wordList); } while (newWord === wordEl.innerText); var newColor; do { newColor = randomChoice(colors); } while (newColor === wordEl.style.color); wordEl.innerText = newWord; wordEl.style.color = newColor; } window.onclick = function () { if (!started) { started = true; document.getElementById("controls").style.display = "none"; changeWord(); setInterval(changeWord, 1000); setInterval(function() { if (hypnoFrequency < hypnoIncrements) { hypnoFrequency++; } }, 5000); } else { document.getElementById("controls").style.display = showControls ? "none" : "block"; showControls = !showControls; } }