rgb-color-utils 又一个前端RGB颜色小工具

rgb-color-utils

A simple utils library for RGB colors which provides some convenient methods such as color interpolation, gradient generation, etc.

Installation

npm install rgb-color-utils

or

yarn add rgb-color-utils

Example Usage

import { parseColor, interpolate, gradientColor } from 'rgb-color-utils';

const colorList = parseColor('#cdab85'); // [205, 171, 133]
const newColor = interpolate('rgb(0, 23, 148)', '#febab5', 0.5); // '#7f69a5'
const colorMap = gradientColor('#bca380', '#00f', 4); // ['#bca380', '#8d7aa0', '#5e52c0', '#2f29df']

API

parseColor(color)

  • color one RGB/HEX color string (rgba(0, 23, 148) or #bf0081)

interpolate(from, to, step)

  • from the starting position RGB/HEX color string (rgba(0, 23, 148) or #bf0081)
  • to the end position color string
  • step the normalized value (between 0 and 1) of the interpolation. A step of 0.5 would be the middle of from and to

gradientColor(from, to, length)

  • from the starting position RGB/HEX color string (rgba(0, 23, 148) or #bf0081)
  • to the end position color string
  • length the length of the gradient colors array.

License

MIT License

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 13,454评论 0 23
  • 好久没有动笔写东西了,这次参加小密圈也是一个新的尝试。以前写读书笔记就像写整理概括似的。 印象最深的是把知识转化为...
    三石_2d3d阅读 1,794评论 0 0
  • 不论将imageview放在relativelayout还是LinearLayout中,如果想让imageview...
    UniThan阅读 13,495评论 2 2
  • 天气很热,我又感觉到了虚无。不知身在哪里,虚浮得很,我想让自己真实,真实在空气。想化成冰激凌,化成四散辐射的触角融...
    柴子恒阅读 2,454评论 0 1