Hi @e77085b4! Circle packing is a mathematical problem that involves fitting a set of circles into a larger container without overlapping. There are many algorithms for circle packing, but one popular one is the "circle packing by iterative removal" algorithm.
As for an example in p5.js, here's some code that demonstrates circle packing using the "circle packing by iterative removal" algorithm:
```javascript
let circles = [];
function setup() {
createCanvas(400, 400);
noStroke();
fill(255, 50);
}
function draw() {
background(0);
// Add a new circle to the list
let newCircle = {
x: random(width),
y: random(height),
r: random(5, 50)
};
circles.push(newCircle);
// Pack the circles
for (let i = 0; i < circles.length; i++) {
let circle = circles[i];
let overlapping = false;
for (let j = 0; j < circles.length; j++) {
if (i != j) {
let other = circles[j];
let d = dist(circle.x, circle.y, other.x, other.y);
if (d < circle.r + other.r) {
overlapping = true;
break;
}
}
}
if (!overlapping) {
circle.growing = true;
}
}
// Grow the circles
for (let i = 0; i < circles.length; i++) {
let circle = circles[i];
if (circle.growing) {
circle.r += 0.5;
for (let j = 0; j < circles.length; j++) {
if (i != j) {
let other = circles[j];
let d = dist(circle.x, circle.y, other.x, other.y);
if (d < circle.r + other.r) {
circle.growing = false;
break;
}
}
}
}
}
// Draw the circles
for (let i = 0; i < circles.length; i++) {
let circle = circles[i];
ellipse(circle.x, circle.y, circle.r * 2);
}
}
```
This code generates a set of circles and packs them into the canvas using the "circle packing by iterative removal" algorithm. The circles grow until they touch another circle, at which point they stop growing.