Published
Edited
Jul 11, 2019
8 stars
Also listed in…
Simulation
Insert cell
Insert cell
Insert cell
{
const context = DOM.context2d(height, height);
context.translate(height / 2, height / 2);
context.beginPath();
context.arc(0, 0, height / 2 - 1, 0, 2 * Math.PI);
context.stroke();
context.beginPath();
context.arc(0, 0, height / 2 - 2, 0, 2 * Math.PI);
context.stroke();
context.fillStyle = "#ccc";
context.fill();
context.clip();
context.lineWidth = 0.1;

const random = d3.randomNormal();

do {
context.fillStyle = "#ffffff07";
context.fillRect(-height / 2, -height / 2, height, height);
context.fillStyle = "black";

for (let i = 0; i < points.length / 2; i++) {
points[2 * i] += random();
points[2 * i + 1] += random() + 0.05;
if (points[2 * i] ** 2 + points[2 * i + 1] ** 2 > (height / 2 - 2) ** 2) {
points[2 * i] *= 0.99;
points[2 * i + 1] *= 0.99;
}
}

context.beginPath();
voronoi.update().render(context);
context.stroke();

yield context.canvas;
} while (true);
}
Insert cell
voronoi = new d3.Delaunay(points).voronoi([
-height / 2 + 1,
-height / 2 + 1,
height / 2 - 1,
height / 2 - 1
])
Insert cell
height = Math.min(600, width)
Insert cell
random = d3.randomNormal(0, height / 8.5)
Insert cell
points = (replay,
Float32Array.from({ length: 2 * ((height ** 2 / 150) | 0) }, random))
Insert cell
d3 = require("d3-delaunay@^5.1", "d3-random@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