randomColor
randomColor copied to clipboard
Exclude colors or hues
Extend the functionality to generate N
(distinct) colors with a list of excludes
that must not appear among the generated set. A typical example would be "background color" and "text color" (B&W).
The excludes should be considered as a part of the colors during the generation process, so the new colors are as far as possible from each other as well from the excludes, this is done in #50
Excluding a certain hue would be a good first step. Is this currently possible?
I prefer this option as well! Are there any plans to develop this new feature?
Great idea, would be nice to have in this lib
I had problem with colors sometimes not dark enough when using dark luminosity (or colors not light enough), so I excluded specific problematic colors something like this for now:
function getColor(luminosity, seed) {
const excludes = [
"#b21051",
"#78ed9f"
];
let color = randomColor({
luminosity: luminosity,
seed: seed
});
while (excludes.includes(color)) {
color = randomColor({ luminosity: luminosity });
}
return color;
}
// use
getColor("dark", "whatever");
I added some commentary to @Xliff's PR #119 which might be of interest to those subscribed to this issue