mindjack/content/hypno/colors/colors.js

48 lines
1.4 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);
2020-11-20 14:04:08 -05:00
} while (newWord === wordEl.textContent);
2020-05-29 16:58:33 -04:00
var newColor;
do {
newColor = randomChoice(colors);
} while (newColor === wordEl.style.color);
2020-11-20 14:04:08 -05:00
wordEl.textContent = newWord;
2020-05-29 16:58:33 -04:00
wordEl.style.color = newColor;
}
document.getElementById("controls").onclick = function (e) {
e.stopPropagation();
}
2020-05-29 16:58:33 -04:00
window.onclick = function () {
if (!started) {
started = true;
document.getElementById("controls").style.display = "none";
document.getElementById("reload").style.display = "inline";
2020-05-29 16:58:33 -04:00
changeWord();
setInterval(changeWord, 1000);
setInterval(function() { if (hypnoFrequency < hypnoIncrements) { hypnoFrequency++; } }, 5000);
} else {
document.getElementById("controls").style.display = showControls ? "none" : "block";
showControls = !showControls;
}
}