Last active
February 7, 2024 03:19
-
-
Save bendc/76c48ce53299e6078a76 to your computer and use it in GitHub Desktop.
Generate nice random colors
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
const randomColor = (() => { | |
"use strict"; | |
const randomInt = (min, max) => { | |
return Math.floor(Math.random() * (max - min + 1)) + min; | |
}; | |
return () => { | |
var h = randomInt(0, 360); | |
var s = randomInt(42, 98); | |
var l = randomInt(40, 90); | |
return `hsl(${h},${s}%,${l}%)`; | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the snippet. Is there a version for directly generating the hex format instead of the hsl format? I need to apply the generated colors on
<input type="color">
, which only accepts the hex format.I can probably add a "hsl to hex" function into the snippet, but that would make the snippet unnecessarily longer.