Skip to content

Instantly share code, notes, and snippets.

@PROPHESSOR
Created August 8, 2018 23:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PROPHESSOR/efb894666e1c78dd4ea364446c5c8e72 to your computer and use it in GitHub Desktop.
Save PROPHESSOR/efb894666e1c78dd4ea364446c5c8e72 to your computer and use it in GitHub Desktop.
Генератор нужного количества случайных цветов в HEX на JavaScript
// 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