getXYs = (data, width, height, points, center) => {
const n = points.length
const c = new Float64Array(n * 2);
const s = new Float64Array(n);
const [cx, cy] = center;
const strength = 0.1
const delaunay = new d3.Delaunay(points);
const voronoi = delaunay.voronoi([0, 0, width, height]);
for (let k = 0; k < 80; ++k) {
c.fill(0);
s.fill(0);
for (let y = 0, i = 0; y < height; ++y) {
for (let x = 0; x < width; ++x) {
const w = data[y * width + x];
i = delaunay.find(x + 0.5, y + 0.5, i);
s[i] += w;
c[i * 2] += w * (x + 0.5);
c[i * 2 + 1] += w * (y + 0.5);
}
}
const w = Math.pow(k + 1, -0.8) * 10;
for (let i = 0; i < n; ++i) {
const x0 = points[i * 2], y0 = points[i * 2 + 1];
const wp = data[Math.floor(y0) * width + Math.floor(x0)];
let x1, y1;
if (wp && s[i]) {
x1 = c[i * 2] / s[i];
y1 = c[i * 2 + 1] / s[i];
} else {
x1 = x0 + (cx - x0) * strength
y1 = y0 + (cy - y0) * strength;
}
points[i * 2] = x0 + (x1 - x0) * 1.8 + (Math.random() - 0.5) * w;
points[i * 2 + 1] = y0 + (y1 - y0) * 1.8 + (Math.random() - 0.5) * w;
}
}
return points
voronoi.update()
}