streamlines
The library builds streamlines for arbitrary vector fields, trying to keep uniform distance
between them.
usage
You can play with the interactive demo, though keep in mind - it's just a demo created in one night.
True value of this repository is in the library itself :).
Demo is here: https://anvaka.github.io/streamlines
More advanced example is wind-map - visualization of the winds
map with evenly spaced streamlines.
get it
Use it with your favorite bundler:
npm install @anvaka/streamlines
Or include a precompiled version:
https://cdn.jsdelivr.net/gh/anvaka/streamlines@v1.3.0/dist/streamlines.min.js
If you are using precompiled version, it will be available under global name window.streamlines
.
use it
var vectorField = p => ({ x: -p.y, y: p.x });
streamlines({
vectorField,
onPointAdded(from, to) {
console.log("point created", from, to);
},
onStreamlineAdded(points) {
console.log("stream line created. Number of points: ", points.length);
}
}).run();
The library allows you to configure various aspects of computation:
streamlines({
vectorField(p) { return p; },
boundingBox: {left: -5, top: -5, width: 10, height: 10},
seed: {x: -1, y: 1},
dSep: 0.5
dTest: 0.25,
timeStep: 0.01,
forwardOnly: false
}).run();
The library does not depend on any particular rendering engine, and can be used in the
browser or node.js environment. However, for your convenience and reference I've added
a simple canvas renderer:
var canvas = document.getElementById("scene");
streamlines({
vectorField(p) {
return { x: -p.y, y: p.x };
},
onPointAdded: streamlines.renderTo(canvas)
}).run();
Here is a JSBin for you to try.
Async
The library is asynchronous in its nature. This is done mostly to give you more control
over streamline construction process.
The downside is that it is harder to understand the code. It is written in a way so that
it can be interrupted at almost every computational step.
If you want to cancel rendering, call dispose
method:
var renderer = streamlines({
vectorField(p) {
return p;
}
});
renderer.run();
renderer.dispose();
If you want to understand the algorithm, please read this paper - the library follows it closely.
More examples
License
MIT