Skip to content

Commit

Permalink
Merge pull request #5 from jalavosus/generator/fill-extra-colors
Browse files Browse the repository at this point in the history
feat(generator): implement fix(?) for issue #4
  • Loading branch information
TimMikeladze committed Apr 26, 2022
2 parents 813f9f1 + 4138b74 commit 181caa7
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions src/util/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ export const generator = async (
const key = options.key || options.k;
const id = options.id ? options.id : customId();

const customCount = options.count || options.c;
const customColors = options.colors || options.cs;

if (width > MAX_DIMENSION || height > MAX_DIMENSION) {
throw new Error(`Dimensions must be no greater than ${MAX_DIMENSION}`);
}
Expand Down Expand Up @@ -171,18 +174,35 @@ export const generator = async (
}
}

const [svg, canvas] = patterns[options.type || options.t || `simple`]({
...allOptions,
colors:
(options.colors || options.cs)?.split(`-`)?.map(fixHexColorString) ||
randomColor({
count,
let colors: string[] =
(options.colors || options.cs)?.split(`-`)?.map(fixHexColorString) ||
randomColor({
count,
hue,
luminosity,
seed,
format,
alpha,
});

if (customColors && customCount && count > colors.length) {
const countDiff = count - colors.length;
colors = [
...colors,
...randomColor({
count: countDiff,
hue,
luminosity,
seed,
format,
alpha,
}),
];
}

const [svg, canvas] = patterns[options.type || options.t || `simple`]({
...allOptions,
colors,
});

await redis.incr(`numberOfImagesCreated`);
Expand Down

0 comments on commit 181caa7

Please sign in to comment.