0.1.0 • Published 5 years ago

ndarray-delaunay v0.1.0

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

ndarray-delaunay

build status

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:

input

To this:

output

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

ParamTypeDescription
imagendarrayThe input image to take the colors from
pointsArrayAn array of arrays, containing x and y coordinates
optionsObjectConfiguration options
options.getDeffunctionA 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.getElementfunctionA function that gets called with the image and coordinates for a triangle and returns a valid dainty element to append to the svg

License

MIT

0.1.0

5 years ago