circles = {
let ctx = canvas2.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
function shuffleArray(array) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
}
function drawCircle(c) {
ctx.beginPath();
ctx.arc(c.x, c.y, c.r, 0, 2 * Math.PI);
ctx.stroke();
}
function circleDist(c1, c2) {
return Math.sqrt(Math.pow(c1.x - c2.x, 2) + Math.pow(c1.y - c2.y, 2)) - (c1.r + c2.r);
}
shuffleArray(validPixelsIdx);
let circles = [];
for (let i=0; i<validPixelsIdx.length; i++) {
let centerX = validPixelsIdx[i][1];
let centerY = validPixelsIdx[i][0];
let radius = Math.random() * (maxR - minR) + minR;
let curr_c = {x: centerX, y: centerY, r: radius};
let dists = circles.map((c) => circleDist(c, curr_c))
let minDist = Math.min(...dists);
if (minDist < 0) continue;
circles.push(curr_c);
drawCircle(curr_c);
}
return circles;
}