0.1.0 • Published 5 years ago
ndarray-delaunay v0.1.0
ndarray-delaunay
apply delaunay triangulation to a collection of points and fill it with colors from an image
This library allows you to triangulate a collection of points and fill the resulting triangles with colors from an image. So you can for example render this image:
To this:
Installation
$ npm install ndarray-delaunay
Example
const util = require('util');
const getPixels = util.promisify(require('get-pixels'));
const fs = require('fs');
const delaunay = require('ndarray-delaunay');
getPixels('./input.png').then(image => {
const svg = delaunay(image, [[0,0],[0,99],[99,99],[99,0],[50,50]]);
fs.writeFileSync('./output.svg', svg);
});
API
delaunay(image, points, options) ⇒ string
Apply delaunay triangulation to a collection of points and fill it with colors from an image
Kind: global function Returns: string - The svg as a string, containing the rendered elements
Param | Type | Description |
---|---|---|
image | ndarray | The input image to take the colors from |
points | Array | An array of arrays, containing x and y coordinates |
options | Object | Configuration options |
options.getDef | function | A function that gets called with the image and coordinates for a triangle and returns a falsey value or a valid dainty element to append to the defs |
options.getElement | function | A function that gets called with the image and coordinates for a triangle and returns a valid dainty element to append to the svg |
License
0.1.0
5 years ago