Fixed up nina's functions

pull/119/head
Maneesh Yadav 2021-05-15 01:35:57 -07:00
rodzic 4b5bb9ccb6
commit f5cd6b8d78
2 zmienionych plików z 64 dodań i 60 usunięć

Wyświetl plik

@ -4,19 +4,19 @@ import * as colorspaces from "colorspaces";
import { ColorTuple, hsluvToHex } from "hsluv";
type RandomPaletteGenerator = (numEntries: number, rng: Random) => string[];
type ColorFunction = (rng: Random) => string[];
export type RandomPaletteAlgorithm =
| "RGB"
| "CIELUV"
| "threevals"
| "huecontrast"
| "randgrey"
| "3v15"
| "3v30"
| "3v45"
| "3v60"
| "3v75"
| "3v90";
| "threev15"
| "threev30"
| "threev45"
| "threev60"
| "threev75"
| "threev90";
export const DEFAULT_RANDOM_PALETTE_ALGORITHM: RandomPaletteAlgorithm =
"threevals";
@ -97,35 +97,9 @@ function createRandGrey(rng: Random): string[] {
return hexcolors;
}
function create3HColor(rng: Random): string[] {
let L = rng.fromGaussian({ mean: 50, stddev: 20 });
let Ls = [L, L, L];
Ls = Ls.map((x) => clamp(x, 0, 100));
let h1 = rng.inInterval({ min: 0, max: 360 }),
h2 = 360 * (((h1 + 120) / 360) % 1),
h3 = 360 * (((h1 + 240) / 360) % 1);
let Hs = [h1, h2, h3];
let S = 100;
let Ss = [S, S, S];
Ss = Ss.map((x) => clamp(x, 0, 100));
//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 create3V180(angle1:number):
number => string[] {
function create3V180(angle1: number):
ColorFunction {
return (rng: Random): string[] => {
let Ls = [25,50,75];
@ -134,6 +108,7 @@ number => string[] {
h2 = 360 * (((h1+angle1) / 360) % 1),
h3 = 360 * (((180-h2) / 360) % 1);
let Hs = [h1, h2, h3];
console.log(Hs);
let Ss = [
rng.fromGaussian({ mean: 100, stddev: 40 }),
@ -152,11 +127,11 @@ number => string[] {
}
}
function create3VColorSimple(rng: Random): string[] {
let lowL_Mean = 25.0,
medL_Mean = 50.0,
hiL_Mean = 75,
lowL_SD = 0,
function create3VColor(rng: Random): string[] {
let lowL_Mean = 20.0,
medL_Mean = 40.0,
hiL_Mean = 70,
lowL_SD = 30.0,
medL_SD = lowL_SD,
hiL_SD = lowL_SD;
@ -171,15 +146,15 @@ function create3VColorSimple(rng: Random): string[] {
//Now we have 3 lightness values, pick a random hue and sat
let h1 = rng.inInterval({ min: 0, max: 360 }),
h2 = 360 * ((h1 + 30)/360 % 1),
h3 = 360 * ((h1 + 195)/360 % 1);
h2 = 360 * (((h1 + 60 * Number(rng.bool(0.5))) / 360) % 1),
h3 = 360 * (((h1 + 180 * Number(rng.bool(0.5))) / 360) % 1);
let Hs = [h1, h2, h3];
let Ss = [
rng.fromGaussian({ mean: 70, stddev: 60 }),
rng.fromGaussian({ mean: 70, stddev: 60 }),
rng.fromGaussian({ mean: 70, stddev: 60 }),
rng.fromGaussian({ mean: 100, stddev: 40 }),
rng.fromGaussian({ mean: 100, stddev: 40 }),
rng.fromGaussian({ mean: 100, stddev: 40 }),
];
Ss = Ss.map((x) => clamp(x, 0, 100));
@ -192,7 +167,6 @@ function create3VColorSimple(rng: Random): string[] {
return hexcolors;
}
/**
* Factory function to take a function that generates a random color
* and return a palette generator that just calls it once for every
@ -233,15 +207,13 @@ const PALETTE_GENERATORS: {
RGB: createSimplePaletteGenerator(createRandomRGBColor),
CIELUV: createSimplePaletteGenerator(createRandomCIELUVColor),
threevals: createTriadPaletteGenerator(create3VColor),
simple3v: createTriadPaletteGenerator(create3VColorSimple),
huecontrast: createTriadPaletteGenerator(create3HColor),
randgrey: createTriadPaletteGenerator(createRandGrey),
3v15: createTriadPaletteGenerator(factory3V180(15)),
3v30: createTriadPaletteGenerator(factory3V180(15)),
3v45: createTriadPaletteGenerator(factory3V180(45)),
3v60: createTriadPaletteGenerator(factory3V180(60)),
3v75: createTriadPaletteGenerator(factory3V180(75)),
3v90: createTriadPaletteGenerator(factory3V180(90))
threev15: createTriadPaletteGenerator(create3V180(15)),
threev30: createTriadPaletteGenerator(create3V180(15)),
threev45: createTriadPaletteGenerator(create3V180(45)),
threev60: createTriadPaletteGenerator(create3V180(60)),
threev75: createTriadPaletteGenerator(create3V180(75)),
threev90: createTriadPaletteGenerator(create3V180(90))
};
export const RANDOM_PALETTE_ALGORITHMS = Object.keys(

44
package-lock.json wygenerowano
Wyświetl plik

@ -29,6 +29,7 @@
"hsluv": "^0.1.0",
"jest": "^26.6.3",
"parcel-bundler": "^1.12.4",
"parcel-plugin-static-files-copy": "^2.6.0",
"prettier": "^2.2.1",
"react": "^17.0.1",
"react-dom": "^17.0.1",
@ -9314,6 +9315,15 @@
"node": ">=0.10.0"
}
},
"node_modules/parcel-plugin-static-files-copy": {
"version": "2.6.0",
"resolved": "https://registry.npmjs.org/parcel-plugin-static-files-copy/-/parcel-plugin-static-files-copy-2.6.0.tgz",
"integrity": "sha512-k3YxdnEQWo1aMfCeBfxgUNJWuUE0O730EGiGBcmWEUOto7f1jM/8oxBKXkVZsXDCO1o00dw5X7CsT+yF0JY4qA==",
"dependencies": {
"minimatch": "3.0.4",
"path": "0.12.7"
}
},
"node_modules/parse-asn1": {
"version": "5.1.6",
"resolved": "https://registry.npmjs.org/parse-asn1/-/parse-asn1-5.1.6.tgz",
@ -9367,6 +9377,15 @@
"node": ">=0.10.0"
}
},
"node_modules/path": {
"version": "0.12.7",
"resolved": "https://registry.npmjs.org/path/-/path-0.12.7.tgz",
"integrity": "sha1-1NwqUGxM4hl+tIHr/NWzbAFAsQ8=",
"dependencies": {
"process": "^0.11.1",
"util": "^0.10.3"
}
},
"node_modules/path-browserify": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/path-browserify/-/path-browserify-0.0.1.tgz",
@ -9406,6 +9425,19 @@
"resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz",
"integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw=="
},
"node_modules/path/node_modules/inherits": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
"integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4="
},
"node_modules/path/node_modules/util": {
"version": "0.10.4",
"resolved": "https://registry.npmjs.org/util/-/util-0.10.4.tgz",
"integrity": "sha512-0Pm9hTQ3se5ll1XihRic3FDIku70C+iHUdT/W926rSgHV5QgXsYbKZN8MSC3tJtSkhuROzvsQjAaFENRXr+19A==",
"dependencies": {
"inherits": "2.0.3"
}
},
"node_modules/pbkdf2": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/pbkdf2/-/pbkdf2-3.1.1.tgz",
@ -17324,9 +17356,9 @@
}
},
"hosted-git-info": {
"version": "2.8.9",
"resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.9.tgz",
"integrity": "sha512-mxIDAb9Lsm6DoOJ7xH+5+X4y1LU/4Hi50L9C5sIswK3JzULS4bwk1FvjdBgvYR4bzT4tuUQiC15FE2f5HbLvYw=="
"version": "2.8.8",
"resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.8.tgz",
"integrity": "sha512-f/wzC2QaWBs7t9IYqB4T3sR1xviIViXJRJTWBlx2Gf3g0Xi5vI7Yy4koXQ1c9OYDGHN9sBy1DQ2AB8fqZBWhUg=="
},
"hsl-regex": {
"version": "1.0.0",
@ -19722,9 +19754,9 @@
}
},
"lodash": {
"version": "4.17.21",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg=="
"version": "4.17.20",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.20.tgz",
"integrity": "sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA=="
},
"lodash.clone": {
"version": "4.5.0",