xxxxxxxxxx
134
class Builder{
constructor(x, y){
this.pos = createVector(x, y);
this.epos = createVector(x, y);
this.evel = createVector(1, 0);
this.evel.setMag(20);
this.vel = createVector(1, 0);
this.chance = 0;
this.active = 0;
this.vs = 0;
this.c = floor(random(cols.length));
this.col = color(cols[this.c]);
this.t = [];
this.t1 = [];
this.a = 0;
}
build(){
this.chance = random(1000);
this.t = get(this.pos.x, this.pos.y);
this.t1 = get(this.epos.x, this.epos.y);
if(this.t[0] !== 180 || this.t1[0] !== 180){
if(this.active == 1){
vertex(this.pos.x, this.pos.y);
vertex(this.epos.x, this.epos.y);
endShape();
this.vs = 0;
this.active = 0;
}
}
if(this.active == 0 && this.t[0] == 180 && this.t1[0] == 180){
if(this.chance > 950){
beginShape(QUAD_STRIP);
this.c = floor(random(cols.length));
this.col = color(cols[this.c]);
fill(this.col);
this.active = 1;
vertex(this.pos.x, this.pos.y);
this.vs ++;
vertex(this.epos.x, this.epos.y);
this.vs++;
}
}
if(this.active == 1){
if(this.chance > 925 && this.chance < 950 && this.t[0] == 180){
vertex(this.pos.x, this.pos.y);
this.vs++;
this.c = floor(random(cols.length));
this.col = cols[this.c];
fill(this.col);
}
if(this.chance > 900 && this.chance < 925 && this.t1[0] == 180){
vertex(this.epos.x, this.epos.y);
this.vs++;
this.c = floor(random(cols.length));
this.col = cols[this.c];
fill(this.col);
}
if(this.chance > 995 && this.vs > 3){
vertex(this.pos.x, this.pos.y);
vertex(this.epos.x, this.epos.y);
endShape()
this.vs = 0;
this.active = 0;
}
}
}
move(){
this.a = (noise(this.pos.x / 800, this.pos.y / 800) * TWO_PI);
// print(this.a);
this.vel.setHeading((noise(this.pos.x / 800, this.pos.y / 800) * TWO_PI) * 100);
this.evel.setHeading(this.vel.heading() + PI / 2);
this.evel.setMag(noise(this.pos.x / 500, this.pos.y / 500) * 50);
this.pos.add(this.vel);
this.epos = p5.Vector.add(this.pos, this.evel);
if(this.pos.x < 0 || this.epos.x < 0){
if(this.active == 1){
vertex(this.pos.x, this.pos.y);
vertex(this.epos.x, this.epos.y);
endShape();
this.vs = 0;
this.active = 0;
}
this.pos.x = random(width);
this.pos.y = random(height);
this.evel.setMag(random(10, 50));
this.epos = p5.Vector.add(this.pos, this.evel);
}
if(this.pos.y < 0 || this.epos.y < 0){
if(this.active == 1){
vertex(this.pos.x, this.pos.y);
vertex(this.epos.x, this.epos.y);
endShape();
this.vs = 0;
this.active = 0;
}
this.pos.x = random(width);
this.pos.y = random(height);
this.evel.setMag(random(10, 50));
this.epos = p5.Vector.add(this.pos, this.evel);
}
if(this.pos.x > width || this.epos.x > width){
if(this.active == 1){
vertex(this.pos.x, this.pos.y);
vertex(this.epos.x, this.epos.y);
endShape();
this.vs = 0;
this.active = 0;
}
this.pos.x = random(width);
this.pos.y = random(height);
this.evel.setMag(random(10, 50));
this.epos = p5.Vector.add(this.pos, this.evel);
}
if(this.pos.y > height || this.epos.y > height){
if(this.active == 1){
vertex(this.pos.x, this.pos.y);
vertex(this.epos.x, this.epos.y);
endShape();
this.vs = 0;
this.active = 0;
}
this.pos.x = random(width);
this.pos.y = random(height);
this.evel.setMag(random(10, 50));
this.epos = p5.Vector.add(this.pos, this.evel);
}
// point(this.pos.x, this.pos.y);
// point(this.epos.x, this.epos.y);
}
}