A radial diffusion-limited aggregation sketch. Link to source files.
//particle list
let Particles = [];
let LDA = [];
let c = [];
//define the distance between agregate (resolution)
let spacing = 10;
///particle count
let pc = 0;
//color range and speed increment
let crange = 30;
let spinc = 500;
function setup(){
createCanvas(800,800)
}
function draw(){
background(0);
//update particle list
for(let i = 0; i < Particles.length; i++){
let pt = Particles[i];
if(pt.stop == 0){
pt.display();
pt.move();
pt.check();
}
if(pt.stop == 1){
Particles.splice(i,1);
}
}
for(let i = 0; i < LDA.length; i++){
let pt = LDA[i];
let ptc = c[i];
stroke(ptc);
point(pt.x,pt.y);
}
//create new particle each frame
if(frameCount%4 == 0){
Particles.push(new Particle());
}
}
class Particle{
constructor(){
this.stop = 0;
this.cc = color(255,255,255);
//set random start posiiton on a cirlce
this.ang = random(2* PI);
this.x = width/2 + (width/2.0) * cos(this.ang);
this.y = height/2 + (height/2.0) * sin(this.ang);
//define speed for particle
this.speedx = (width/2.0-this.x)/spinc;
this.speedy = (height/2.0-this.y)/spinc;
}
display(){
stroke(this.cc);
strokeWeight(spacing);
point(this.x,this.y);
}
move(){
if(this.stop == 0){
this.x = this.x + this.speedx;
this.y = this.y + this.speedy;
}
}
check(){
//chceck to see if particle is first to reach center
if(dist(this.x,this.y,width/2,height/2) < spacing && pc < 1){
this.stop = 1;
this.x = width/2;
this.y = height/2;
this.cc = color(random(255),random(255),random(255));
append(LDA,createVector(this.x,this.y));
append(c,this.cc);
pc++;
}
//check to see if particles position is within the spacing
//of an agregated particle and then set its color to a new color
//based on the agregated particles color and within the preset color range
for(let i = 0; i < LDA.length; i++){
let pt = LDA[i];
let ptc = c[i];
if(dist(this.x,this.y,pt.x,pt.y) < spacing && this.stop == 0){
this.stop = 1;
let R = red(ptc) + random(-crange,crange);
let G = green(ptc) + random(-crange,crange);
let B = blue(ptc) + random(-crange,crange);
this.cc = color(R,G,B);
append(LDA,createVector(this.x,this.y));
append(c,color(R,G,B));
pc++;
}
}
}
}