mindjack/content/hypno/colors/colors.js

48 lines
1.4 KiB
JavaScript

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.textContent);
var newColor;
do {
newColor = randomChoice(colors);
} while (newColor === wordEl.style.color);
wordEl.textContent = newWord;
wordEl.style.color = newColor;
}
document.getElementById("controls").onclick = function (e) {
e.stopPropagation();
}
window.onclick = function () {
if (!started) {
started = true;
document.getElementById("controls").style.display = "none";
document.getElementById("reload").style.display = "inline";
changeWord();
setInterval(changeWord, 1000);
setInterval(function() { if (hypnoFrequency < hypnoIncrements) { hypnoFrequency++; } }, 5000);
} else {
document.getElementById("controls").style.display = showControls ? "none" : "block";
showControls = !showControls;
}
}