{
const w = 600, h = 600;
const maxDepth = 9, speed = .003;
const p1 = [w/3, h/2], p2 = [w-(w/3), h/2];
const sd = depth => depth/maxDepth;
const scaleT = t => d => t + (1-sd(d))*.4;
const ctx = DOM.context2d(w, h);
ctx.fillStyle = '#000';
ctx.fillRect(0, 0, w, h);
ctx.lineCap = 'round'; ctx.lineJoin = 'round';
ctx.lineWidth = 2;
ctx.strokeStyle = 'hsla(0,0%,100%,.5)';
const [x1, y1] = p1, [x2, y2] = p2;
let t = .21;
while(true) {
const layers = Array.from({length: maxDepth + 1}).map(() => []);
for(let tri of split(x1, y1, x2, y2, maxDepth, scaleT(t))) {
layers[tri.depth].push(tri);
}
for(let tri of split(x1, y1, x2, y2, maxDepth, scaleT(t+1))) {
layers[tri.depth].push(tri);
}
ctx.fillStyle = 'hsla(0,0%,0%,1)';
ctx.fillRect(0, 0, w, h);
layers
.filter((l, d) => d < 3 || d > 5)
.forEach((l, d) => {
ctx.beginPath();
for(let i = 0; i < l.length; i++) {
ctx.moveTo(l[i].x1, l[i].y1);
ctx.lineTo(l[i].x3, l[i].y3);
ctx.lineTo(l[i].x2, l[i].y2);
ctx.lineTo(l[i].x1, l[i].y1);
}
ctx.stroke();
});
yield ctx.canvas;
t = (t + speed) % 1;
}
}