From 4ee126442e9a80189414e6733f0c26552abbbcf3 Mon Sep 17 00:00:00 2001 From: Maneesh Yadav Date: Thu, 29 Apr 2021 20:16:52 -0700 Subject: [PATCH] added randgrey color rule --- lib/random-colors.ts | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/random-colors.ts b/lib/random-colors.ts index 34b9741..0f18cc1 100644 --- a/lib/random-colors.ts +++ b/lib/random-colors.ts @@ -9,7 +9,8 @@ export type RandomPaletteAlgorithm = | "RGB" | "CIELUV" | "threevals" - | "huecontrast"; + | "huecontrast" + | "randgrey"; export const DEFAULT_RANDOM_PALETTE_ALGORITHM: RandomPaletteAlgorithm = "threevals"; @@ -68,6 +69,28 @@ function createRandomCIELUVColor(rng: Random): string { return randColorHex; } +function createRandGrey(rng: Random): string[] { + let L1 = rng.inInterval({ min: 0, max: 100 }); + let L2 = rng.inInterval({ min: 0, max: 100 }); + let L3 = rng.inInterval({ min: 0, max: 100 }); + + let Ls = [L1, L2, L3]; + + let h = 0; + let Hs = [h, h, h]; + + let S = 0; + let Ss = [S, S, S]; + + //zip + let hsls = Ls.map((k, i) => [Hs[i], Ss[i], k]); + let hexcolors = hsls.map((x) => hsluvToHex(x as ColorTuple)); + + //scramble order + hexcolors = rng.uniqueChoices(hexcolors, hexcolors.length); + return hexcolors; +} + function create3HColor(rng: Random): string[] { let L = rng.fromGaussian({ mean: 50, stddev: 20 }); @@ -176,6 +199,7 @@ const PALETTE_GENERATORS: { CIELUV: createSimplePaletteGenerator(createRandomCIELUVColor), threevals: createTriadPaletteGenerator(create3VColor), huecontrast: createTriadPaletteGenerator(create3HColor), + randgrey: createTriadPaletteGenerator(createRandGrey), }; export const RANDOM_PALETTE_ALGORITHMS = Object.keys(