Created
October 5, 2017 20:43
-
-
Save blrobin2/b3c4eb55b3b163b7b2e5c88bc715bf03 to your computer and use it in GitHub Desktop.
My implementation of this: https://www.reddit.com/r/programminghorror/comments/74ch79/there_exists_things_that_i_am_not_proud_of/
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
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <title>Colors</title> | |
| <style> | |
| body { | |
| background-color: black; | |
| font-size: 10em; | |
| font-family: sans-serif; | |
| text-align: center; | |
| } | |
| span { | |
| display: inline-block; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <script> | |
| const generateLayout = () => { | |
| const rows = 1 | |
| const columns = 10 | |
| const fragment = document.createDocumentFragment() | |
| for (let r = 1; r <= rows; r++) { | |
| const row = document.createElement('div') | |
| for (let c = 1; c <= columns; c++) { | |
| const col = document.createElement('span') | |
| row.appendChild(col) | |
| } | |
| fragment.appendChild(row) | |
| } | |
| document.body.appendChild(fragment) | |
| return document.querySelectorAll('span') | |
| } | |
| const randomNumber = max => Math.floor(Math.random() * max) | |
| const randomNumberBetween0And10 = () => randomNumber(9) | |
| const randomColor = () => randomNumber(255) | |
| const randomRGB = () => `rgb(${randomColor()},${randomColor()},${randomColor()})` | |
| const party = spans => spans.forEach(el => { | |
| el.innerHTML = randomNumberBetween0And10() | |
| el.style.color = randomRGB() | |
| }) | |
| const app = () => { | |
| const spans = generateLayout() | |
| setInterval(party.bind(null, spans), 30) | |
| } | |
| app() | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment