https://github.com/parksben/rgb-color-utils
A simple utils library for RGB colors which provides some convenient methods such as color interpolation, gradient generation, etc.
https://github.com/parksben/rgb-color-utils
color javascript utils
Last synced: about 1 year ago
JSON representation
A simple utils library for RGB colors which provides some convenient methods such as color interpolation, gradient generation, etc.
- Host: GitHub
- URL: https://github.com/parksben/rgb-color-utils
- Owner: parksben
- Created: 2017-10-31T13:34:02.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-10-31T16:37:48.000Z (over 8 years ago)
- Last Synced: 2025-02-21T04:05:02.452Z (over 1 year ago)
- Topics: color, javascript, utils
- Language: JavaScript
- Homepage:
- Size: 17.6 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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
```javascript
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