A vertical diffusion-limited aggregation sketch that resembles coral growth. Link to source files.
let coordinates = [];
let space = 5;
let numx;
let numy;
let Ccolor = [];
function setup() {
createCanvas(800,800);
numx = int(width/space) + space;
numy = int(height/space)+1;
for (var x = 0; x < numx; x++) {
coordinates[x] = []; // create nested array
Ccolor[x] = [];
for (var y = 0; y < numy; y++) {
coordinates[x][y] = 0;
Ccolor[x][y] = color(0);
}
}
}
function draw() {
background(0);
for(let cycles = 0; cycles < 4; cycles++){
let xcor = int(random(1,numx-3));
for (let i = 0; i < numy; i++) {
if((coordinates[xcor][i] != 0) || (coordinates[xcor+1][i] != 0) || (coordinates[xcor-1][i] != 0)){
coordinates[xcor][i-1] = 1;
if(coordinates[xcor][i] != 0){
Ccolor[xcor][i-1] = color(red(Ccolor[xcor][i]) + random(-20,20),green(Ccolor[xcor][i]) + random(-20,20),blue(Ccolor[xcor][i]) + random(-20,20));
}
if(coordinates[xcor+1][i] != 0){
Ccolor[xcor][i-1] = color(red(Ccolor[xcor+1][i] ) + random(-20,20),green(Ccolor[xcor+1][i] ) + random(-20,20),blue(Ccolor[xcor+1][i] ) + random(-20,20));
}
if(coordinates[xcor-1][i] != 0){
Ccolor[xcor][i-1] = color(red(Ccolor[xcor-1][i]) + random(-20,20),green(Ccolor[xcor-1][i]) + random(-20,20),blue(Ccolor[xcor-1][i]) + random(-20,20));
}
i = numy+1;
}
if(i == numy - 1){
coordinates[xcor][i] = 1;
Ccolor[xcor][i] = color(random(255),random(255),random(255));
}
}
}
for (let x = 0; x < numx; x++) {
for (let y = 0; y < numy; y++) {
if (coordinates[x][y] == 1){
noStroke();
fill(Ccolor[x][y]);
rect(((x*space)-space), y*space, space, space);
}
}
}
}