draw-triangles-2d
draws a simplicial complex using Canvas2D context
Last updated 12 years ago by mattdesl .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install draw-triangles-2d 
SYNC missed versions from official npm registry.

draw-triangles-2d

stable

Draws indexed triangles from a simplicial complex using Canvas2D context.

Positions and cells look like this:

{ positions: [ [25,25], [50, 50], ... ], cells: [ [0,1,2], [1,2,3], ... ] }

Demo:

var drawTriangles = require('draw-triangles-2d')

var path = [ [25, 25], [40, 30], [50, 75], [125, 15] ]

//get a thick polyline
var mesh = require('extrude-polyline')({ 
    thickness: 20,
    miterLimit: 1.5
}).build(path)

function render(ctx, width, height) {
    ctx.clearRect(0,0,width,height)

    ctx.beginPath()
    drawTriangles(ctx, mesh.positions, mesh.cells)
    ctx.strokeStyle = 'black'
    ctx.lineJoin = 'bevel'
    ctx.stroke()
}

Simplicial complexes are a common ground between various modules, such as triangulate-contours, extrude-polyline, etc.

Usage

NPM

draw(context, positions, cells[, start, end])

Draws the 2D positions and triangle cells (i.e. indices into positions) to the given context. You can specify start (inclusive) and end (exclusive) indices to only render a sub range of the cells. These values defualt to 0 and the length of cells, respectively.

License

MIT, see LICENSE.md for details.

Current Tags

  • 1.0.0                                ...           latest (12 years ago)

1 Versions

  • 1.0.0                                ...           12 years ago
Maintainers (1)
Downloads
Total 5
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 0
Last Month 1
Dependencies (0)
None
Dev Dependencies (3)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE