xxxxxxxxxx
70
class Tri {
constructor(x, y, index) {
this.pos1 = createVector(x, y);
this.move = createVector(0, -10);
this.pos2 = p5.Vector.add(this.pos1, this.move);
this.t1 = createVector(0, 20);
this.t2 = createVector(0, 20);
this.pos3 = p5.Vector.add(this.pos1, this.t1);
this.pos4 = p5.Vector.add(this.pos1, this.t2);
this.index = index;
this.turn = PI;
this.xoff = 0.001;
this.yoff = 0.1
this.h = this.move.heading();
this.c = 0;
this.col = color(cols[this.c]);
}
update() {
this.yoff = this.yoff + 0.001
this.move.setMag(noise(this.yoff) * 30 + 5);
this.t1.setMag(noise(this.yoff) * 30 + 10);
this.t2.setMag(noise(this.yoff) * 30 + 10);
if(this.pos1.x < 0) {
this.pos1.x = this.pos1.x + width;
this.pos2.x = this.pos2.x + width;
this.pos3.x = this.pos3.x + width;
this.pos4.x = this.pos4.x + width;
}
if(this.pos1.y < 0) {
this.pos1.y = this.pos1.y + height;
this.pos2.y = this.pos2.y + height;
this.pos3.y = this.pos3.y + height;
this.pos4.y = this.pos4.y + height;
}
if(this.pos1.x > width) {
this.pos1.x = this.pos1.x - width;
this.pos2.x = this.pos2.x - width;
this.pos3.x = this.pos3.x - width;
this.pos4.x = this.pos4.x - width;
}
if(this.pos1.y > height) {
this.pos1.y = this.pos1.y - height;
this.pos2.y = this.pos2.y - height;
this.pos3.y = this.pos3.y - height;
this.pos4.y = this.pos4.y - height;
}
this.h = this.move.heading();
this.t1.setHeading(this.h + (PI / 1.5))
this.t2.setHeading(this.h - (PI / 1.5))
this.pos3 = p5.Vector.add(this.pos1, this.t1);
this.pos4 = p5.Vector.add(this.pos1, this.t2);
this.c ++;
if(this.c == cols.length) this.c = 0;
this.col = color(cols[this.c]);
stroke(0);
fill(this.col)
triangle(this.pos1.x, this.pos1.y, this.pos2.x, this.pos2.y, this.pos3.x, this.pos3.y);
triangle(this.pos1.x, this.pos1.y, this.pos2.x, this.pos2.y, this.pos4.x, this.pos4.y);
noStroke();
circle(this.pos1.x, this.pos1.y, this.move.mag());
this.xoff = this.xoff + 0.1;
this.turn = noise(this.xoff) * (PI * PI);
this.move.setHeading(this.turn);
this.pos1.x = this.pos2.x;
this.pos1.y = this.pos2.y;
this.pos2 = p5.Vector.add(this.pos1, this.move);
}
}