class RobinsonTriangle {
constructor({ points, type, depth = 0 }) {
this.type = type;
this.points = points;
this.depth = depth;
}
get path() {
let [a, b, c] = this.points;
return lineGen([b, a, c]);
}
get svg() {
let [a, b, c] = this.points;
let strokeWidth = 0.1 * Math.pow(0.87, depth);
return htl.svg`<g>
<path d="${lineGen([b, a, c])}" fill="${this.color}"></path>
<path
d="${lineGen([b, c])}"
fill="none"
stroke="${this.color}"
stroke-width="${strokeWidth}"
></path>
<path
d="${lineGen([b, a, c])}"
fill="none"
stroke="white"
stroke-width="${strokeWidth}"
></path>
</g>`;
}
get color() {
return this.type === "acute" ? "steelblue" : "rgb(160,40,5)";
}
flip() {
let [a, b, c] = this.points;
return new RobinsonTriangle({ type: this.type, points: [a, c, b] });
}
subdivide() {
let [a, b, c] = this.points;
if (this.type === "acute") {
let p = lerpxy(a, b, 1 / PHI);
return [
new RobinsonTriangle({
type: "acute",
points: [c, p, b],
depth: this.depth + 1
}),
new RobinsonTriangle({
type: "obtuse",
points: [p, c, a],
depth: this.depth + 1
})
];
} else {
let q = lerpxy(b, a, 1 / PHI);
let r = lerpxy(b, c, 1 / PHI);
return [
new RobinsonTriangle({
type: "obtuse",
points: [r, c, a],
depth: this.depth + 1
}),
new RobinsonTriangle({
type: "obtuse",
points: [q, r, b],
depth: this.depth + 1
}),
new RobinsonTriangle({
type: "acute",
points: [r, q, a],
depth: this.depth + 1
})
];
}
}
}