xxxxxxxxxx
52
class Tri{
constructor(x1, y1, index, c){
if(tris.length < 1){
this.x1 = x1 * 20 + random(-10, 10);
} else {
this.x1 = tris[index - 1].x2
}
if(tris.length < 1){
this.y1 = y1 * 20 + random(-10, 10);
} else {
this.y1 = tris[index - 1].y2
}
if(tris.length < 1){
this.x2 = x1 * 20 + 20 + random(-10, 10);
} else {
this.x2 = tris[index - 1].x3
}
if(tris.length < 1){
this.y2 = y1 * 20 + random(-10, 10);
} else {
this.y2 = tris[index - 1].y3
}
// this.y1 = y1 * 20 + random(-10, 10);
// this.x2 = (x1 * 20) + 20 + random(-10, 10);
// this.y2 = y1 * 20 + random(-10, 10);
this.x3 = this.x2 + random(-20, 20);
if(this.x3 < 0){
this.x3 = 0;
}
if(this.x3 > width){
this.x3 = width;
}
this.y3 = this.y2 + random(-20, 20);
if(this.y3 < 0){
this.y3 = 0;
}
if(this.y3 > height){
this.y3 = height;
}
this.lx1 = (this.x1 + this.x2) / 2;
this.ly1 = (this.y1 + this.y2) / 2;
this.index = index;
this.c = c;
}
show(){
c = floor(map(this.index, 0, tris.length, 0, cols.length));
stroke(cols[c]);
line(this.lx1, this.ly1, this.x3, this.y3);
triangle(this.x1, this.y1, this.x2, this.y2, this.x3, this.y3);
}
}