xxxxxxxxxx
98
function setup() {
createCanvas(900, 900);
// blendMode(ADD);
cols = ["#121617","#002d7a","#3a5fcf","#2fc2ee","#96e5ed","#f1e4ed","#917bb7","#db3a34","#ff661f","#ffb41f"];
time = 0;
time1 = 0;
time2 = 1;
closest = 0;
pressure = [];
dens = 50;
rdens = 75;
riders = [];
for(x = 0; x < width / dens; x++){
for(y = 0; y < height / dens; y++){
pressure[pressure.length] = new Pressure(x * dens + random(-dens, dens), y * dens + random(-dens, dens), pressure.length);
}
}
for(x = 0; x < width / rdens; x++){
for(y = 0; y < height / rdens; y++){
riders[riders.length] = new Rider(x * rdens + random(-rdens, rdens), y * rdens + random(-rdens, rdens), riders.length);
}
}
background(255);
}
function draw() {
// background(255, 20);
time = time + 0.0005;
time1 = time1 + 0.005;
time2 = time2 + 0.005;
for(i = 0; i < pressure.length; i++){
pressure[i].update();
}
for(i = 0; i < riders.length; i++){
riders[i].update();
}
}
class Pressure{
constructor(x, y, index){
this.opos = createVector(x, y);
this.pos = createVector(x, y);
this.vel = createVector(1, 0);
}
update(){
this.pos.x = this.opos.x + map(noise(this.opos.x / 250, this.opos.y / 250, time1), 0, 1, -1, 1) * dens;
this.pos.y = this.opos.y + map(noise(this.opos.x / 250, this.opos.y / 250, time2), 0, 1, -1, 1) * dens;
this.vel.setMag(noise(this.pos.x / 100, this.pos.y / 100, time) * 4);
this.vel.setHeading(noise(this.pos.x / 250, this.pos.y / 250, time) * TWO_PI * 4);
// stroke(255);
// point(this.pos.x, this.pos.y);
}
}
class Rider{
constructor(x, y, index){
this.index = index;
this.pos = createVector(x, y);
this.opos = createVector(x, y);
this.spos = createVector(x, y);
this.vel = createVector(1, 0);
this.vel.setHeading(random(TWO_PI));
this.maxSpeed = 1 + this.index % 10;
this.test = createVector(1, 0);
this.ctest = createVector(1, 0);
this.closest = 0;
this.i = 0;
this.col = color(cols[floor(this.index % 10)])
}
update(){
for(this.i = 0; this.i < pressure.length; this.i++){
this.ctest = p5.Vector.sub(pressure[this.closest].pos, this.pos)
this.test = p5.Vector.sub(pressure[this.i].pos, this.pos);
if(this.test.mag() < this.ctest.mag()){
this.closest = this.i;
}
}
this.vel.add(pressure[this.closest].vel);
if(this.vel.mag() > this.maxSpeed) this.vel.setMag(this.maxSpeed);
this.opos.x = this.pos.x;
this.opos.y = this.pos.y;
this.pos.add(this.vel);
// this.col.setAlpha(5);
stroke(this.col);
line(this.pos.x, this.pos.y, this.opos.x, this.opos.y);
if(this.pos.x < 0 || this.pos.x > width || this.pos.y < 0 || this.pos.y > height){
this.pos.x = this.spos.x + random(-rdens, rdens);
this.pos.y = this.spos.y + random(-rdens, rdens);
this.vel.setMag(0);
}
}
}