xxxxxxxxxx
function setup(){
createCanvas(windowWidth, windowHeight)
circles = []
packCircles(50000)
background(0)
stroke(255)
noFill()
drawCircles()
noLoop()
}
function packCircles(N){
for(let n = 0; n < N; n++){
let randX = random(windowWidth)
let randY = random(windowHeight)
let s = random(5,100)
let placeable = true
for(let k = 0; k < circles.length; k++){
let otherC = circles[k]
let d = dist(randX, randY, otherC.x, otherC.y)
if(d < otherC.s/2 + s/2+2){
placeable = false
break
}
}
if(placeable){
circles.push({x: randX, y: randY, s: s})
}
}
}
function drawCircles(){
for(let n = 0; n < circles.length; n++){
let currC = circles[n]
ellipse(currC.x, currC.y, currC.s)
}
}