xxxxxxxxxx
62
function setup() {
createCanvas(1920, 1080);
background(220);
leader = new Leader(0, 0);
followers = [];
cols = ["#ffc857","#ee9550","#e9724c","#d74845","#c5283d","#a41c32","#471d33","#3e2e6d","#255f85","#269480"];
for(i = 0; i < height / 5; i++){
followers[followers.length] = new Follower(0,i * 5 + 5, i);
}
}
function draw() {
leader.update();
for(a = 0; a < followers.length; a++){
followers[a].update();
}
}
class Leader{
constructor(x, y){
this.pos = createVector(x, y);
this.vel = createVector(1, 0);
}
update(){
this.vel.setHeading(map(noise(this.pos.x / 25, this.pos.y / 25), 0, 1, -1, 1));
this.pos.add(this.vel);
// if(frameCount % 5 == true){
strokeWeight(1);
point(this.pos.x, this.pos.y);
// }
}
}
class Follower{
constructor(x, y, index){
this.pos = createVector(x, y);
this.pos2 = createVector(x, y);
this.vel = createVector(1, 0);
this.index = index;
this.c = cols[this.index % cols.length];
}
update(){
if(this.index < 1){
this.vel.setHeading(leader.vel.heading() + map(noise(this.pos.x / 500, this.pos.y / 500), 0, 1, -0.1, 0.1));
}
else{
this.vel.setHeading(map(followers[this.index - 1].vel.heading() + map(noise(this.pos.x / 500, this.pos.y / 500, this.index / 50), 0, 1, -0.2, 0.2), -1.2, 1.2, -1, 1));
}
this.pos2.add(this.vel);
// if(frameCount % 5 == true){
stroke(this.c);
strokeWeight(2);
line(this.pos.x, this.pos.y, this.pos2.x, this.pos2.y);
// }
this.pos.add(this.vel);
// this.pos2 = this.pos;
}
}