{
const context = DOM.context2d(imageWidth, imageHeight, 1);
context.drawImage(image, 0, 0, imageWidth, imageHeight);
const imageData = context.getImageData(0, 0, imageWidth, imageHeight);
const traceData = imagetracer.imagedataToTracedata(imageData, {
colorsampling: 0,
colorquantcycles: 1,
numberofcolors: 7,
linefilter: true,
ltres: 0.0001
});
const linesData = traceData.layers
.flat()
.map((d) => d.segments)
.flat()
.filter((d) => d.type === "L")
.sort((a, b) => d3.ascending(a.y1, b.y1));
const lines = linesData.map(
(d) => htl.svg`<line ${{ ...d }} stroke="black" />`
);
const voronoiCells = getVoronoiCells(
linesData.map((d) => [d.x1, d.y1]).filter(() => Math.random() < 0.2),
{ width: imageWidth, height: imageHeight }
);
const voronoiPaths = voronoiCells
.map(
({ pathDefinition }) =>
htl.svg`<path fill="none" stroke="black" d=${pathDefinition} />`
)
.filter((d) => d.getTotalLength() > 90);
const points = linesData.map(
(d) =>
htl.svg`<circle r="5" stroke="black" fill="none" cx=${d.x1} cy=${d.y1} />`
);
return htl.html`<svg width="400px" viewBox=${`0 0 ${imageWidth} ${imageHeight}`}>
${voronoiPaths}
</svg>`;
}