randomColor icon indicating copy to clipboard operation
randomColor copied to clipboard

Exclude colors or hues

Open breznak opened this issue 9 years ago • 5 comments

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

breznak avatar Jan 19 '16 10:01 breznak

Excluding a certain hue would be a good first step. Is this currently possible?

spacedragn avatar Aug 25 '16 23:08 spacedragn

I prefer this option as well! Are there any plans to develop this new feature?

JimCraane avatar Feb 20 '18 08:02 JimCraane

Great idea, would be nice to have in this lib

armved avatar Dec 05 '18 09:12 armved

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");

sarfraznawaz2005 avatar Jan 14 '19 09:01 sarfraznawaz2005

I added some commentary to @Xliff's PR #119 which might be of interest to those subscribed to this issue

davidmerfield avatar Jul 14 '20 20:07 davidmerfield