GithubHelp home page GithubHelp logo

leopoldthecoder / colorpath Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 0.0 690 KB

🎨Find paths for your color.

Home Page: https://leopoldthecoder.github.io/colorpath/

License: MIT License

Makefile 0.71% JavaScript 96.67% Shell 2.61%

colorpath's Introduction

colorpath

Build Status Coverage Status npm

There's a path for everyone, and my path always leads me back to you

安装

npm install colorpath

使用

colorpath 支持以下三个函数的运算和逆运算:

  • tint
  • shade
  • mix

引入 colorpath:

import clp from 'colorpath'

接下来就可以使用以下 API(参数中的 sourceColordestinationColormixer 均支持十六进制和 RGB 两种表示法):

  • tint(sourceColor, percentage)
clp.tint('#ff08d5', 0.4) //[255, 107, 230]
  • findTint(sourceColor, destinationColor)
clp.findTint('#ff08d5', '#ff6be6') //0.4028
  • shade(sourceColor, percentage)
clp.shade('#ffc8d5', 0.4) //[153, 120, 128]
  • findShade(sourceColor, destinationColor)
clp.findShade('#ffc8d5', '#997880') //0.3997
  • mix(sourceColor, mixer, percentage)
clp.mix('#ffc8d5', 'd3985a', 0.4) //[229, 171, 139]
  • findMixer(sourceColor, destinationColor)
clp.findMixer('#ffc8d5', '#e5ab8b') //{ mixer: [ 180, 117, 0 ], percentage: 0.6526 }
  • findPath(sourceColor, destinationColor)
clp.findPath('#ff08d5', '#ff6be6') //{ method: 'tint', percentage: 0.4028 }
clp.findPath('#ffc8d5', '#997880') //{ method: 'shade', percentage: 0.3997 }
clp.findPath('#ffc8d5', '#e5ab8b') //{ method: 'mix', mixer: [ 180, 117, 0 ], percentage: 0.6526 }

注意:若 findTintfindShade 无解,则会抛出一个错误;而 findPath 会先尝试调用 findTintfindShade,若发现无解会调用 findMixer。因此,如果不确定两种颜色之间是否存在 tint 或 shade 的关系,建议直接使用 findPath

命令行工具

安装

npm install -g colorpath

使用

$ clp <arguments> <method>

其中 arguments 为调用参数,method 为调用方法。上述例子中的 clp.findPath('#ffc8d5', '#e5ab8b') 对应的命令行调用为:

$ clp ffc8d5 e5ab8b --find-path

colorpath's People

Contributors

leopoldthecoder avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.