colorin
Version:
colors Interpolation
114 lines (85 loc) • 2.48 kB
Markdown
colors interpolate




[](https://maptalks.github.io/colorin/test/base.html)
[](https://maptalks.github.io/colorin/test/pie.html)
[](https://maptalks.github.io/colorin/test/mtk-points.html)
[](https://maptalks.github.io/colorin/test/mtk-lines.html)
[](https://maptalks.github.io/colorin/test/mtk-polygons.html)
[](https://maptalks.github.io/colorin/test/zoomstop.html)
[](https://maptalks.github.io/colorin/test/customsize.html)
[](https://maptalks.github.io/colorin/test/covid-19.html)
[](https://maptalks.github.io/colorin/test/echarts-bar.html)
[](https://maptalks.github.io/colorin/test/echarts-calendar.html)
maptalks.js already has this feature built-in
[](https://maptalks.org/examples/en/style/color-interpolate/#style_color-interpolate)
* CDN
```html
<script src="https://unpkg.com/colorin/dist/colorin.js"></script>
```
* NPM
```sh
npm i colorin
yarn add colorin
```
in nodejs, you need dynamic registerCanvas,you can use [@napi-rs/canvas](https://github.com/Brooooooklyn/canvas) or [node-canvas](https://github.com/Automattic/node-canvas)
```sh
npm i @napi-rs/canvas
yarn add @napi-rs/canvas
```
```js
const {
ColorIn,
registerCanvas
} = require('colorin');
const {
createCanvas
} = require('@napi-rs/canvas');
const canvas = createCanvas(1, 1);
registerCanvas(canvas);
```
+ colors `Color collection`
```js
import {
ColorIn
} from 'colorin';
const colors = [
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[]
];
const ci = new ColorIn(colors);
const [r, g, b, a] = ci.getColor(11);
//if you use cdn
const ci = new colorin.ColorIn(colors);
```
+ getColor(stop) `get color by stop`
```js
const [r, g, b, a] = ci.getColor(11);
```
+ getImageData() `get canvas image data`
```js
const imgData = ci.getImageData();
```