xxxxxxxxxx
75
let movers = [];
let cols = ["#1fbfff","#1fdaff","#2ceef2","#8ccfb9","#d2b04b","#ffb01f","#fd8f21","#fc6722","#ea4334","#d7474c"]
function setup() {
createCanvas(2880, 1920);
for(i = 0; i < 7; i++){
movers[movers.length] = new Mover(random(0, width), height, movers.length);
movers[movers.length] = new Mover(random(0, width), 0, movers.length);
movers[movers.length] = new Mover(0, random(0, height), movers.length);
movers[movers.length] = new Mover(width, random(0, height), movers.length);
}
blendMode(ADD);
background(0);
}
function draw() {
for(a = 0; a < 200; a++){
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.vel.setHeading(-PI);
this.turn = createVector(1, 0);
this.wiggle = createVector(0,1);
this.wiggle.setMag(1);
this.xoff = 0.0001;
this.tav = -PI;
this.tat = 0.001;
this.taw = 0;
this.i = 0;
this.col = color(cols[this.index % cols.length])
}
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.taw = this.vel.heading() + map(noise(this.cpos.x / 1000, this.cpos.y / 1000, this.index / 100), 0, 1, -1, 1);
}else{
this.taw = this.vel.heading();
}
this.wiggle.setHeading(this.taw);
this.vel.add(this.wiggle);
this.vel.limit(2);
this.npos = p5.Vector.add(this.cpos, this.vel);
this.col.setAlpha(2);
stroke(this.col);
strokeWeight(1);
line(this.cpos.x, this.cpos.y, this.npos.x, this.npos.y);
this.cpos.add(this.vel);
if(this.cpos.x > width){
this.cpos.x = 10;
this.cpos.y = random(10, height - 10);
}
if(this.cpos.y > height){
this.cpos.x = random(10, width - 10);
this.cpos.y = 10;
}
if(this.cpos.x < 0){
this.cpos.x = width -10;
this.cpos.y = random(10, height - 10);
}
if(this.cpos.y < 0){
this.cpos.x = random(10, width - 10);
this.cpos.y = height -10;
}
}
}