mindjack/content/hypno/colors/colors.js

43 lines
1.3 KiB
JavaScript
Raw Normal View History

2020-05-29 16:58:33 -04:00
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;
}
}