Created
June 19, 2016 06:48
-
-
Save lyntco/03e73db8ad6302ea7ced3c7de1defca7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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