blobs = {
const newCircle = circleGenerator(50)
let blobs = []
for (let i = 0; i < n_blobs; i++) {
let x_y_coords = newCircle(n_blobs)
blobs.push({
x_coord: x_y_coords[0],
y_coord: x_y_coords[1],
color: colorScale(random.value()),
blob_random: 0.7 + Math.random(),
scaling_factor: 0
})
blobs[i].blob = []
for (let r = 0; r <= n_points_blob; r++) {
blobs[i].blob.push({
radius: (1+ Math.random() * 0.2 * blobs[i].blob_random),
angle: Math.PI * 2 / n_points_blob * r,
})
}
}
const ctx = DOM.context2d(width, height)
gsap.to(blobs, {
scaling_factor: 100,
onUpdate: animate,
duration: 5
})
function animate() {
ctx.globalCompositeOperation = "soft-light"
ctx.clearRect(0, 0, width, height)
blobs.forEach((d, i) => {
d.blob.forEach((data,index) => {
d.blob[index].radius += d.blob[index].radius/d.scaling_factor
})
ctx.save();
ctx.translate(d.x_coord, d.y_coord)
ctx.fillStyle = d.color
ctx.beginPath()
line.context(ctx)(d.blob)
ctx.fill()
ctx.closePath()
ctx.restore()
})
const voronoi = d3.voronoi()
.x((d) => d.x_coord)
.y((d) => d.y_coord);
const diagram = voronoi(blobs);
const links = diagram.links();
ctx.globalCompositeOperation = "source-over";
ctx.beginPath();
links.forEach((l) => {
ctx.moveTo(l.source.x_coord, l.source.y_coord);
ctx.lineTo(l.target.x_coord, l.target.y_coord);
});
ctx.strokeStyle = "rgba(255,255,255,0.4)";
ctx.stroke();
ctx.beginPath();
blobs.forEach((b) => {
ctx.moveTo(b.x_coord + 2.5, b.y_coord);
ctx.arc(b.x_coord, b.y_coord, 2.5, 0, Math.PI * 2, false);
});
ctx.fillStyle = "white";
ctx.fill();
}
return ctx.canvas
}