# colorpath
[![Build Status](https://travis-ci.org/Leopoldthecoder/colorpath.svg?branch=master)](https://travis-ci.org/Leopoldthecoder/colorpath)
[![Coverage Status](https://coveralls.io/repos/github/Leopoldthecoder/colorpath/badge.svg?branch=master)](https://coveralls.io/github/Leopoldthecoder/colorpath?branch=master)
[![npm](https://img.shields.io/npm/v/colorpath.svg)](https://www.npmjs.org/package/colorpath)
> There's a path for everyone, and my path always leads me back to you
安装
npm install colorpath
使用
colorpath 支持以下三个函数的运算和逆运算:
- tint
- shade
- mix
引入 colorpath:
接下来就可以使用以下 API(参数中的 sourceColor
、destinationColor
和 mixer
均支持十六进制和 RGB 两种表示法):
- tint(sourceColor, percentage)
clp //[255, 107, 230]
- findTint(sourceColor, destinationColor)
clp //0.4028
- shade(sourceColor, percentage)
clp //[153, 120, 128]
- findShade(sourceColor, destinationColor)
clp //0.3997
- mix(sourceColor, mixer, percentage)
clp //[229, 171, 139]
- findMixer(sourceColor, destinationColor)
clp //{ mixer: [ 180, 117, 0 ], percentage: 0.6526 }
- findPath(sourceColor, destinationColor)
clp //{ method: 'tint', percentage: 0.4028 }clp //{ method: 'shade', percentage: 0.3997 }clp //{ method: 'mix', mixer: [ 180, 117, 0 ], percentage: 0.6526 }
注意:若
findTint
或findShade
无解,则会抛出一个错误;而findPath
会先尝试调用findTint
和findShade
,若发现无解会调用findMixer
。因此,如果不确定两种颜色之间是否存在 tint 或 shade 的关系,建议直接使用findPath
。
命令行工具
安装
npm install -g colorpath
使用
$ clp <arguments> <method>
其中 arguments
为调用参数,method
为调用方法。上述例子中的 clp.findPath('#ffc8d5', '#e5ab8b')
对应的命令行调用为:
$ clp ffc8d5 e5ab8b --find-path