Public
Edited
Feb 1, 2024
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
radius = 2.5
Insert cell
minDistance = 40
Insert cell
maxDistance = 60
Insert cell
positions = Float64Array.from({length: n * 2}, (_, i) => Math.random() * (i & 1 ? height : width))
Insert cell
velocities = new Float64Array(n * 2)
Insert cell
delaunay = new d3.Delaunay(positions)
Insert cell
// voronoi = new d3.Delaunay(positions).voronoi([0, 0, width, height]);
Insert cell
function nearestNeighbor(i) {
const {points} = delaunay;
let minDistance = Infinity;
let minNeighbor;
const x0 = points[i * 2];
const y0 = points[i * 2 + 1];
for (const neighbor of delaunay.neighbors(i)) {
const x1 = points[neighbor * 2];
const y1 = points[neighbor * 2 + 1];
const distance = (x0 - x1) ** 2 + (y0 - y1) ** 2;
if (distance < minDistance) {
minDistance = distance;
minNeighbor = neighbor;
}
}
return minNeighbor;
}
Insert cell
height = 600
Insert cell
margin = 60
Insert cell
// n = 1000
Insert cell
d3 = require("d3-delaunay@^5.1")
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more