xxxxxxxxxx
59
function setup() {
createCanvas(900,900);
background("#FFF1E0");
// blendMode(ADD);
cols = ["#ffc857","#ee9550","#e9724c","#d74845","#c5283d","#a41c32","#471d33","#3e2e6d","#255f85","#269480"];
verts = [];
dens = 50;
time = 0;
time2 = 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.01;
time2 = time2 + 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])
this.col.setAlpha(5);
}
update(){
if(noise(this.pos.x / 500, this.pos.y / 500, time) > 0){
this.vel = createVector(1, 0);
this.vel.setHeading(noise(this.pos.x / 500, this.pos.y / 500, time2) * 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 < -25 || this.pos.x > width +25 || this.pos.y < -25 || this.pos.y > height +25){
this.pos.x = this.opos.x + random(-dens, dens);
this.pos.y = this.opos.y + random(-dens, dens);
}
}
}