Default compute from analogous

This commit is contained in:
Jorge Bolois 2023-03-13 02:27:47 +01:00
parent 741e1127df
commit bf9053d45f
2 changed files with 55 additions and 17 deletions

View File

@ -4,28 +4,66 @@ import tinycolor from 'tinycolor2';
program.command('gen <color>')
.description('Generates multiple colors from a given color')
.option('-a, --amount <n>', 'Amount of darken', 10)
.option('-a, --amount <n>', 'Amount of darken', 12.5)
.option('-c, --complementary', 'Generate complementary colors instead of analogous')
.action((color, options) => {
const primary = tinycolor(color);
const amount = options.amount;
logColor(primary, 'primary');
const darkPrimary = primary.clone().darken(amount);
logColor(darkPrimary, 'dark primary');
const darkerPrimary = darkPrimary.clone().darken(amount);
logColor(darkerPrimary, 'darker primary');
const secondary = primary.complement();
logColor(secondary, 'secondary');
const darkSecondary = secondary.clone().darken(amount);
logColor(darkSecondary, 'dark secondary');
const darkerSecondary = darkSecondary.clone().darken(amount);
logColor(darkerSecondary, 'darker secondary');
const primary = tinycolor(color);
if (options.complementary) {
complementary(primary, amount)
} else {
analogous(primary, amount);
}
});
program.parse(process.argv);
function logColor(color, name) {
const { r, g, b } = color.toRgb()
console.log(`\x1b[48;2;${r};${g};${b}m COLOR \x1b[0m [${name.toUpperCase()}] ${color.toHexString()} `);
console.log(`\x1b[48;2;${r};${g};${b}m ${color.toHexString()} \x1b[0m [${name.toUpperCase()}]`);
}
function analogous(primary, amount) {
_primary(primary, amount);
_separator();
const analogous = primary.analogous(12, 90);
_secondary(analogous[2], amount);
_separator();
_secondary(analogous[5], amount);
_separator();
_secondary(analogous[8], amount);
_separator();
_secondary(analogous[11], amount);
}
function complementary(primary, amount) {
_primary(primary, amount);
_separator();
const secondary = primary.complement();
_secondary(secondary, amount);
}
function _primary(color, amount) {
logColor(color, 'primary');
const darkPrimary = color.clone().darken(amount);
logColor(darkPrimary, 'dark primary');
const darkerPrimary = darkPrimary.clone().darken(amount);
logColor(darkerPrimary, 'darker primary');
}
function _secondary(color, amount) {
logColor(color, 'secondary');
const darkSecondary = color.clone().darken(amount);
logColor(darkSecondary, 'dark secondary');
const darkerSecondary = darkSecondary.clone().darken(amount);
logColor(darkerSecondary, 'darker secondary');
}
function _separator() {
console.log('------------------------------');
}

View File

@ -1,7 +1,7 @@
{
"name": "@midefos/colorgen",
"type": "module",
"version": "0.1.0",
"version": "0.1.1",
"description": "Color generator",
"bin": {
"colorgen": "./colorgen.js"