A simple (maybe fake) voronoi implementation. Diminishing circles drawn each frame give the impression of a voronoi diagram. Link to source files.
//particle list
let Mounds = [];
//define the distance between agregate (resolution)
let spacing = 3;
///particle count
let pc = 0;
//color range and speed increment
let crange = 30;
let spinc = 500;
function setup(){
createCanvas(800,800);
background(0);
for(let i = 0; i < 20; i++){
Mounds.push(new Mound(random(width), random(height)));
}
}
function draw(){
//update particle list
for(let i = 0; i < Mounds.length; i++){
let md = Mounds[i];
if(md.radius > md.stop){
md.display();
md.update();
}
}
}
class Mound{
constructor(x,y){
this.x = x;
this.y = y;
this.radius = 300;
this.a = 0;
this.end = this.radius;
this.stop = this.radius-this.end
this.sc = color(random(255),random(255),random(255),this.a);
this.ec = color(random(255),random(255),random(255));
this.Rspeed = (red(this.ec) - red(this.sc))/this.end;
this.Gspeed = (green(this.ec) - green(this.sc))/this.end;
this.Bspeed = (blue(this.ec) - blue(this.sc))/this.end;
this.cc = this.sc;
this.grow = random(0.5) + 0.5;
}
display(){
fill(this.cc);
noStroke();
ellipse(this.x,this.y,this.radius,this.radius);
}
update(){
this.radius -= 1;
let newR = red(this.cc) + this.Rspeed;
let newG = green(this.cc) + this.Gspeed;
let newB = blue(this.cc) + this.Bspeed;
this.cc = color(newR,newG,newB,this.a);
//this.y -=this.grow;
this.a++;
}
}
function keyPressed() {
if (key == " ") {
background(0);
for(let i = 0; i < 20; i++){
Mounds.push(new Mound(random(width), random(height)));
}
}
}