Last active
February 13, 2018 21:17
-
-
Save JonathanZWhite/85a44d1ad1fa02fb0435c2542e444ec0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function dots(width, height, density) { | |
for (let i = 0; i < density; i += 1) { | |
createDot( | |
Math.floor(Math.random() * width), | |
Math.floor(Math.random() * height), | |
); | |
} | |
} | |
function createDot(x, y) { | |
const elem = document.createElement('div'); | |
const colors = ['#BBC8FA', '#BBE6FA', '#FADCBB']; | |
const color = colors[Math.floor(Math.random() * colors.length)]; | |
const dotSize = Math.floor(Math.random() * 6) + 4; | |
const styles = [ | |
`left: ${x}px;`, | |
`top: ${y}px;`, | |
`background: ${color};`, | |
`height: ${dotSize};`, | |
`width: ${dotSize};`, | |
]; | |
elem.setAttribute('class', 'dot'); | |
elem.setAttribute('style', styles.join('')); | |
document.getElementsByTagName('body')[0].appendChild(elem); | |
return elem; | |
} | |
export default dots; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment