Published
Edited
Nov 6, 2020
11 forks
Importers
61 stars
Insert cell
Insert cell
Insert cell
canvas = {
const n = 500 << 1;
const points = Float64Array.from({length: n}, (_, i) => Math.random() + (i & 1 ? height : width) / 2);
const delaunay = new d3.Delaunay(points);
const context = DOM.context2d(width, height);
context.lineCap = "square";
const voronoi = delaunay.voronoi([0, 0, width, height]);
for (let i = 0; i < 1200; ++i) {
context.clearRect(0, 0, width, height);
context.beginPath();
voronoi.render(context);
context.strokeStyle = "red";
context.stroke();
context.beginPath();
for (let i = 0; i < n; i += 2) {
const cell = voronoi.cellPolygon(i >> 1);
if (cell === null) continue;
const x0 = points[i], y0 = points[i + 1];
const [x1, y1] = d3.polygonCentroid(cell);
context.moveTo(x0, y0);
context.lineTo(points[i] = x0 + (x1 - x0) * omega, points[i + 1] = y0 + (y1 - y0) * omega);
}
context.strokeStyle = "black";
context.stroke();
yield context.canvas;
voronoi.update();
}
}
Insert cell
height = 600
Insert cell
d3 = require("d3-delaunay@5", "d3-polygon@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