Default compute from analogous
This commit is contained in:
parent
741e1127df
commit
bf9053d45f
70
colorgen.js
70
colorgen.js
@ -4,28 +4,66 @@ import tinycolor from 'tinycolor2';
|
|||||||
|
|
||||||
program.command('gen <color>')
|
program.command('gen <color>')
|
||||||
.description('Generates multiple colors from a given 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) => {
|
.action((color, options) => {
|
||||||
const primary = tinycolor(color);
|
|
||||||
const amount = options.amount;
|
const amount = options.amount;
|
||||||
|
const primary = tinycolor(color);
|
||||||
logColor(primary, 'primary');
|
if (options.complementary) {
|
||||||
const darkPrimary = primary.clone().darken(amount);
|
complementary(primary, amount)
|
||||||
logColor(darkPrimary, 'dark primary');
|
} else {
|
||||||
const darkerPrimary = darkPrimary.clone().darken(amount);
|
analogous(primary, 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');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
program.parse(process.argv);
|
program.parse(process.argv);
|
||||||
|
|
||||||
function logColor(color, name) {
|
function logColor(color, name) {
|
||||||
const { r, g, b } = color.toRgb()
|
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('------------------------------');
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@midefos/colorgen",
|
"name": "@midefos/colorgen",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"version": "0.1.0",
|
"version": "0.1.1",
|
||||||
"description": "Color generator",
|
"description": "Color generator",
|
||||||
"bin": {
|
"bin": {
|
||||||
"colorgen": "./colorgen.js"
|
"colorgen": "./colorgen.js"
|
||||||
|
Loading…
Reference in New Issue
Block a user