Created
August 8, 2018 23:51
-
-
Save PROPHESSOR/efb894666e1c78dd4ea364446c5c8e72 to your computer and use it in GitHub Desktop.
Генератор нужного количества случайных цветов в HEX на JavaScript
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
// Copyright (c) PROPHESSOR 2018 | |
const mult = 128; | |
const count = 256; | |
function random(min, max) { | |
return Math.floor(Math.random() * max) + min; | |
} | |
function generate() { | |
return `#${random(0, 255).toString(16)}${random(0, 255).toString(16)}${random(0, 255).toString(16)}`; | |
} | |
for(let i = 0; i < count; i++) { | |
const div = document.createElement('div'); | |
const hex = generate(); | |
div.style=`position:absolute; top: 0; left: ${i * mult}px; background: ${hex}; width: ${mult}px; height: ${mult}px`; | |
div.innerHTML = hex; | |
document.querySelector('#test').appendChild(div); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment