Skip to content

Instantly share code, notes, and snippets.

@lyntco
Created June 19, 2016 06:48
Show Gist options
  • Save lyntco/03e73db8ad6302ea7ced3c7de1defca7 to your computer and use it in GitHub Desktop.
Save lyntco/03e73db8ad6302ea7ced3c7de1defca7 to your computer and use it in GitHub Desktop.
let disco, playing = false;
const dots = document.getElementsByTagName('rect');
const box = document.getElementsByTagName('g')[0];
const getRandomNumber = () => {
return Math.floor(Math.random() * 255) + 1;
};
const getRandomCol = () => {
return `rgb(${getRandomNumber()}, ${getRandomNumber()}, ${getRandomNumber()})`;
};
const gitDisco = () => {
for (let i = 0; i < dots.length; i++) {
dots[i].style.fill = getRandomCol();
}
};
const startDisco = () => {
if (!playing) {
playing = !playing;
disco = setInterval(gitDisco, 500);
} else {
playing = !playing;
clearInterval(disco);
}
};
box.addEventListener('click', startDisco);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment