[github地址:https://github.com/ABCDdouyae…]
gradient-string
用於在終端列印出好看的漸變文字
- 普通用法
console.log(gradient(`cyan`, `pink`)(`Hello world!`));
let a = `so beautiful!`
let b = gradient(`red`, `green`);
console.log(b(a));
let c = gradient([`yellow`, `orange`]);
console.log(c(a));
- 色值寫法可以是各種形式
let coolGradient = gradient([
tinycolor(`#FFBB65`), // tinycolor object
{r: 0, g: 255, b: 0}, // RGB object
{h: 240, s: 1, v: 1, a: 1}, // HSVa object
`rgb(120, 120, 0)`, // RGB CSS string
`gold` // named color
]);
- rainbaw 彩虹色?
console.log(gradient.rainbow(`It`s a rainbow!`))
- multiline 輸出文字量大,可以保證文字垂直對齊
let arr = [
` 。*☆∴。 。∴☆*。`,
` 。★*゚゚*★∵★*゚゚*★。`,
` ☆゚ ゚☆゚ ゚☆`,
` ★* ♡ I. ♡ *★ `,
` ゚☆。♥ LOVE. ♥ 。 ☆゚`,
` *★。♡F.C.F♡ 。★*`,
` ∵☆。 。☆∵`,
` ゚*★。。★*゚`,
` ゚*☆ `,
];
console.log(gradient(`#fff`, `#000`).multiline(arr.join(`
`)))
- 可以設定從左到右的漸變百分比
let colorPool = gradient([
{color:`#fff`, pos: 0.1},
{color:`red`, pos: 0.7},
{color:`yellow`, pos: 1}
]);
console.log(colorPool.multiline(arr.join(`
`)));
- 設定漸變方式
const redToGreen = gradient(`red`, `green`);
const str = `■`.repeat(48);
console.log(redToGreen(str));
console.log(redToGreen(str, {interpolation: `hsv`}));
console.log(redToGreen(str, {interpolation: `hsv`, hsvSpin: `long`}));