xxxxxxxxxx
46
let movers = [];
let cols = ["#1fbfff","#1fdaff","#2ceef2","#8ccfb9","#d2b04b","#ffb01f","#fd8f21","#fc6722","#ea4334","#d7474c"];
let dens = 25;
function setup() {
createCanvas(900, 900);
for(i = 0; i < width; i++){
movers[movers.length] = new Mover(i * dens, height / 2, movers.length);
}
// blendMode(ADD);
background(0);
}
function draw() {
for(i = 0; i < movers.length; i++){
movers[i].update();
}
}
class Mover{
constructor(x, y, index){
this.index = index;
this.cpos = createVector(x, y);
this.npos = createVector(x, y);
this.vel = createVector(0, -1);
this.c = this.index % cols.length;
this.col = color(cols[this.c]);
// this.col.setAlpha(2);
}
update(){
// this.xoff = this.xoff + 0.0000001;
if(this.cpos.x > 10 && this.cpos.y > 10 && this.cpos.x < (width - 10) && this.cpos.y < (height - 10)){
this.vel.setHeading(this.vel.heading() + map(noise(this.cpos.x / 1000, this.cpos.y / 1000, ), 0, 1, -1, 1));
}
this.npos = p5.Vector.add(this.cpos, this.vel);
stroke(this.col);
strokeWeight(1);
line(this.cpos.x, this.cpos.y, this.npos.x, this.npos.y);
this.cpos.add(this.vel);
}
}