Published
Edited
Sep 27, 2020
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
x = d3.randomUniform(settings.size)
Insert cell
y = d3.randomUniform(settings.size)
Insert cell
nPoints = d3.randomUniform(settings.minPoints, settings.maxPoints)
Insert cell
opacity = d3
.scaleLinear()
.domain([0, settings.size])
.range([1, 0])
Insert cell
fill = d3
.scaleLinear()
.domain([0, settings.size])
.range(["#FFD700", settings.background])
Insert cell
polygons = {
const polygons = [];

while (polygons.length < settings.count) {
const n = nPoints(),
poly = [];

while (poly.length < n) {
poly.push([x(), y()]);
}

const triangles = [
...d3.Delaunay.from([
...[[0, 0], [0, settings.size]],
...poly
]).trianglePolygons()
].map(d => {
const points = d.slice(0, -1),
[cx, cy] = d3.polygonCentroid(points);

return {
points,
center: [cx, cy],
opacity: opacity(cx)
};
});

polygons.push(triangles);
}

return polygons;
}
Insert cell
Insert cell
Insert cell
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