xxxxxxxxxx
61
let circles = [];
let minSize = 3;
let maxSize = 200;
let minHue = 0;
let maxHue = 360;
function setup() {
colorMode(HSB)
createCanvas(800, 600);
for (let i = 0; i < 1000; i++) {
let validCircle = false;
let attempts = 0;
while (!validCircle && attempts < 1000) {
let x = random(width);
let y = random(height);
let r = random(minSize, maxSize);
let overlap = false;
// Check if the circle is within the canvas boundaries
if (x - r < 0 || x + r > width || y - r < 0 || y + r > height) {
attempts++;
continue;
}
for (let j = 0; j < circles.length; j++) {
let other = circles[j];
let d = dist(x, y, other.x, other.y);
if (d < r + other.r && d > abs(r - other.r)) {
overlap = true;
break;
}
}
if (!overlap) {
let area = PI * r * r;
let scaledArea = pow(area / (PI * maxSize * maxSize), 0.1); // Exponential scaling
let hue = map(scaledArea, 0, 1, minHue, maxHue);
let saturation = 70 //map(scaledArea, 0, 1, 0, 255);
let val = map(scaledArea, 0, 1, 0, 255);
let colorValue = color(hue, saturation, val);
circles.push({ x, y, r, color: colorValue });
validCircle = true;
}
attempts++;
}
}
// Sort circles by radius in descending order
circles.sort((a, b) => b.r - a.r);
}
function draw() {
background(255); // Set the background to white
for (let circle of circles) {
// Draw the circle with its color
fill(circle.color);
noStroke();
ellipse(circle.x, circle.y, circle.r * 2, circle.r * 2);
}
}