xxxxxxxxxx
93
class Point{
constructor(x, y, z, index){
this.opos = createVector(x, y, z);
this.pos = createVector(x, y, z);
this.vel = createVector(1, 0, 0);
this.push = createVector(1, 0, 0);
stroke(0);
strokeWeight(map(this.pos.z, - depth, depth, 10, 0));
this.index = index;
this.c = floor(this.index % cols.length);
this.col = color(cols[this.c]);
this.scale = 1000;
this.history = [];
this.i = 0;
this.lines = 4;
// this.tick = 0;
}
update(){
this.nf = map(noise(this.pos.x / this.scale, this.pos.y / this.scale, this.pos.z / this.scale), 0, 1, -1, 1);
this.nf2 = map(noise(this.pos.y / this.scale, this.pos.z / this.scale, this.pos.x / this.scale), 0, 1, -1, 1);
if(this.push.mag() > 150 && this.push.mag() < 175){
this.vel = p5.Vector.fromAngles(this.nf * TWO_PI * 2, this.nf2 * TWO_PI, 1);
}
this.vel = p5.Vector.fromAngles(this.nf * TWO_PI * 2, this.nf2 * TWO_PI, 1);
// this.push = p5.Vector.sub(this.pos, avoid);
// if(this.push.mag() < 150){
// this.vel.add(this.push);
// }
// if(this.push.mag() > 175){
// this.push.mult(-1);
// this.vel.add(this.push);
// }
this.vel.setMag(4);
strokeWeight(2);
// this.pos.y = this.nf * height;
this.pos.add(this.vel);
if(this.pos.x < - width){
this.pos.x = random(-width, width);
this.pos.y = random(-height, height);
this.pos.z = random(-depth, depth);
this.history.splice(0, this.lines);
}
if(this.pos.y < - height){
this.pos.x = random(-width, width);
this.pos.y = random(-height, height);
this.pos.z = random(-depth, depth);
this.history.splice(0, this.lines);
}
if(this.pos.z < - depth){
this.pos.x = random(-width, width);
this.pos.y = random(-height, height);
this.pos.z = random(-depth, depth);
this.history.splice(0, this.lines);
}
if(this.pos.x > width){
this.pos.x = random(-width, width);
this.pos.y = random(-height, height);
this.pos.z = random(-depth, depth);
this.history.splice(0, this.lines);
}
if(this.pos.y > height){
this.pos.x = random(-width, width);
this.pos.y = random(-height, height);
this.pos.z = random(-depth, depth);
this.history.splice(0, this.lines);
}
if(this.pos.z > depth){
this.pos.x = random(-width, width);
this.pos.y = random(-height, height);
this.pos.z = random(-depth, depth);
this.history.splice(0, this.lines);
}
if(frameCount % 1 == 0){
this.history[this.history.length] = createVector(this.pos.x, this.pos.y, this.pos.z);
}
if(this.history.length > this.lines & frameCount % 1 == 0){
this.history.splice(0, 1);
}
if(this.history.length > 2){
for(this.i = 0; this.i < this.history.length - 1; this.i++){
stroke(this.col);
line(this.history[this.i + 1].x, this.history[this.i + 1].y, this.history[this.i + 1].z, this.history[this.i].x, this.history[this.i].y, this.history[this.i].z);
}
}
// point(this.pos.x, this.pos.y, this.pos.z)
}
}