Published
Edited
Mar 10, 2019
1 fork
27 stars
Insert cell
Insert cell
canvas = {
const context = DOM.context2d(width, height);
const polygons = Array.from(new d3.Delaunay(points).voronoi([0, 0, width, height]).cellPolygons());
for (let i = 0; i < iterations; i++) {
context.beginPath();
for (const P of polygons) {
context.moveTo(...P[0]);
for (let j = 1, m = P.length; j < m; ++j) context.lineTo(...P[j]);
context.closePath();
const p0 = P.shift();
const p1 = P[0];
const t = Math.min(0.5, 4 / Math.hypot(p0[0] - p1[0], p0[1] - p1[1]));
const p2 = [p0[0] * (1 - t) + p1[0] * t, p0[1] * (1 - t) + p1[1] * t];
P.push(p2);
}
context.fillStyle = d3.interpolateCubehelixDefault(i / iterations);
context.fill();
yield context.canvas;
}
}
Insert cell
points = Array.from({length: n << 1}, (_, i) => Math.random() * (i & 1 ? height : width))
Insert cell
iterations = 500
Insert cell
n = 100
Insert cell
height = Math.max(600, width)
Insert cell
d3 = require("d3-delaunay@4", "d3-scale-chromatic@1")
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more