xxxxxxxxxx
65
let vanishingPoint1;
let vpv1;
let vanishingPoint2;
let vpv2;
let tracers = [];
function setup() {
createCanvas(900, 900);
vanishingPoint1 = createVector(random(width / 2), height / 2);
vpv1 = createVector(1, 0);
vanishingPoint2 = createVector(random(width / 2, width), height / 2);
vpv2 = createVector(1, 0);
for(i = 0; i < 1000; i++){
tracers[tracers.length] = new Tracer(random(width), random(height), tracers.length);
}
}
function draw() {
background(0);
vpv1.setHeading(noise(vanishingPoint1.x / 200, vanishingPoint1.y / 200) * TWO_PI * 4);
vpv2.setHeading(noise(vanishingPoint2.x / 200, vanishingPoint2.y / 200) * TWO_PI * 4);
vanishingPoint1.add(vpv1);
vanishingPoint2.add(vpv2);
for(i = 0; i < tracers.length; i++){
tracers[i].update();
}
}
class Tracer{
constructor(x, y, index){
this.index = index;
this.chance = random(2);
if(this.chance > 1){
this.vp = vanishingPoint1;
this.max = sqrt(sq((this.vp.x - width) * -1) + sq(height / 2));
} else {
this.vp = vanishingPoint2;
this.max = sqrt(sq((width - this.vp.x)) + sq(height / 2));
}
this.pos1 = createVector(x, y);
this.vel1 = p5.Vector.sub(this.vp, this.pos1);
this.angle = p5.Vector.sub(this.pos1, this.vp);
this.angle.setMag(random(20, 80));
this.pos2 = p5.Vector.add(this.pos1, this.angle);
this.vel2 = p5.Vector.sub(this.vp, this.pos2);
this.dist1 = p5.Vector.sub(this.pos1, this.vp);
this.dist2 = p5.Vector.sub(this.pos2, this.vp);
}
update(){
stroke(255);
line(this.pos1.x, this.pos1.y, this.pos2.x, this.pos2.y);
this.vel1 = p5.Vector.sub(this.vp, this.pos1);
this.vel2 = p5.Vector.sub(this.vp, this.pos2);
this.dist1 = p5.Vector.sub(this.vp, this.pos1);
if(this.dist1.mag() < 1) tracers[this.index] = new Tracer(random(width), random(height), this.index);
this.vel1.setMag(map(this.dist1.mag(), 0, this.max, 2, 10));
this.pos1.add(this.vel1);
this.dist2 = p5.Vector.sub(this.vp, this.pos2);
this.vel2.setMag(map(this.dist2.mag(), 0, this.max, 2, 10));
this.pos2.add(this.vel2);
}
}