xxxxxxxxxx
67
class Diamond {
constructor(_x, _y, _r, _colr, _colg, _colb, _strW) {
this.x = _x;
this.y = _y;
this.r = _r;
this.colr = _colr;
this.colg = _colg;
this.colb = _colb;
this.strW = _strW
}
show() {
stroke(Col, this.colg, this.colb);
strokeWeight(this.strW);
angle1 = map(millis(), 0, 1000, 0, 180);
angle2 = map(millis(), 0, Shap, 180, 0);
push();
translate(this.x, this.y);
beginShape();
vertex(constrain(Siz * cos(angle1), -Siz, Siz), 0);
vertex(0, constrain(Siz * sin(angle1), -Siz, Siz));
vertex(constrain(Siz * cos(angle2), -Siz, Siz), 0);
vertex(0, constrain(Siz * sin(angle2), -Siz, Siz));
endShape();
rotate(180);
beginShape();
vertex(constrain(Siz * cos(angle1), -Siz, Siz), 0);
vertex(0, constrain(Siz * sin(angle1), -Siz, Siz));
vertex(constrain(Siz * cos(angle2), -Siz, Siz), 0);
vertex(0, constrain(Siz * sin(angle2), -Siz, Siz));
endShape();
pop();
}
move() {
this.x += random(-5, 5);
this.y += random(-5, 5);
}
intersect(other) {
let d = dist(this.x, this.y, other.x, other.y);
return (d < (this.r + other.r) / 2);
}
fillColor() {
fill(Col, this.colg, this.colb);
push();
translate(this.x, this.y);
beginShape(TRIANGLES);
vertex(constrain(Siz * cos(angle1), -Siz, Siz), 0);
vertex(0, constrain(Siz * sin(angle1), -Siz, Siz));
vertex(constrain(Siz * cos(angle2), -Siz, Siz), 0);
vertex(0, constrain(Siz * sin(angle2), -Siz, Siz));
endShape();
rotate(180);
beginShape(TRIANGLES);
vertex(constrain(Siz * cos(angle1), -Siz, Siz), 0);
vertex(0, constrain(Siz * sin(angle1), -Siz, Siz));
vertex(constrain(Siz * cos(angle2), -Siz, Siz), 0);
vertex(0, constrain(Siz * sin(angle2), -Siz, Siz));
endShape();
pop();
}
}