xxxxxxxxxx
function setup() {
createCanvas(windowWidth, windowHeight);
background(255);
document.documentElement.style.overflow = "hidden";
noLoop();
}
function draw() {
const largeur = windowWidth;
const hauteur = windowHeight;
class Circle{
constructor(width, height){
this.x = Math.random()*width;
this.y = Math.random()*height;
this.radius = 0.1;
this.width = width;
this.height = height;
}
placerHasard(){
this.x = Math.random()*this.width;
this.y = Math.random()*this.height;
}
intersect(element){
let xx = this.x-element.x;
let yy = this.y-element.y;
let calc = Math.sqrt(Math.pow(xx,2) + Math.pow(yy,2));
return calc<(this.radius+element.radius);
}
intersectAll(liste){
for(var i in liste){
if(this.intersect(liste[i])){
return true;
}
}
return false;
}
grossir(liste){
while(this.valid(liste)){
this.radius += 0.1;
}
this.radius -= 0.1;
}
outBordure(){
let cacheX = this.x+this.radius;
let cacheY = this.y+this.radius;
let cacheXX = this.x-this.radius;
let cacheYY = this.y-this.radius;
return cacheXX>0 && cacheYY>0 && cacheX<this.width && cacheY<this.height;
}
valid(liste){
return !this.intersectAll(liste) && this.outBordure();
}
draw(ctxD){
fill(Math.random()*255, Math.random()*255, Math.random()*255);
noStroke();
ellipse(this.x, this.y, this.radius*2, this.radius*2);
}
}
var liste = [];
for(var i = 0; i<700; i++){
let circle = new Circle(largeur, hauteur);
while(!circle.valid(liste)){
circle.placerHasard();
}
circle.grossir(liste);
circle.draw();
liste.push(circle);
}
}