xxxxxxxxxx
56
function setup() {
createCanvas(900,900);
background(0);
cols = ["#ecffe7","#c9f8b5","#bde8a2","#b1d78f","#a8cc82","#ff82c0","#ff96c8","#ffaad0","#ffbed8","#ffd2df"];
verts = [];
dens = 50;
time = 0;
for(x = 0; x < width / dens; x++){
for(y = 0; y < height / dens; y++){
verts[verts.length] = new Vert(x * dens + random(-dens, dens), y * dens + random(-dens, dens), verts.length);
}
}
}
function draw() {
time = time + 0.0001;
for(a = 0; a < verts.length; a++){
verts[a].update();
}
}
class Vert{
constructor(x, y, index){
this.pos = createVector(x, y);
this.opos = createVector(x, y);
this.vel = createVector(0, 0);
this.index = index;
this.meas = createVector(1, 0);
this.i = 0;
this.col = color(cols[this.index % cols.length])
}
update(){
if(noise(this.pos.x / 500, this.pos.y / 500, time) > 0.4){
this.vel = createVector(1, 0);
this.vel.setHeading(noise(this.pos.x / 500, this.pos.y / 500, time) * TWO_PI * 4);
}
else{
this.vel.setMag(0);
}
this.pos.add(this.vel);
for(this.i = 0; this.i < verts.length; this.i++){
this.meas = p5.Vector.sub(this.pos, verts[this.i].pos);
if(this.meas.mag() < 30 && this.i !== this.index){
stroke(this.col);
line(this.pos.x, this.pos.y, verts[this.i].pos.x, verts[this.i].pos.y);
}
}
if(this.pos.x < 0 || this.pos.x > width || this.pos.y < 0 || this.pos.y > height){
this.pos.x = this.opos.x + random(-dens, dens);
this.pos.y = this.opos.y + random(-dens, dens);
}
}
}