function* draw() {
const context = DOM.context2d(width, height);
context.translate(width / 2, width / 3);
let t = 0;
let points = [];
for (let i = 0; i < n; ++i) {
const p = new Point([0, 0, 3], i);
points.push(p);
}
let trace = [];
let play = true;
while (play) {
yield Promises.delay(20).then(() => {
t += 1;
context.clearRect(-width / 2, -width / 2, width, width);
context.beginPath();
context.rect(-width / 2, 5, width, -width / 2);
context.clip();
line([-width / 2, 5], [width / 2, 5], context, {
color: "rgba(150,150,150,0.9)"
});
points.forEach(p => p.draw(context));
const nextPoints = updatePointsPosition(points, t, context);
trace.push(nextPoints);
drawTrace(trace, context);
if (t > tMax) {
play = false;
let maxPoints = findMax(trace);
maxPoints.forEach(p => p.draw(context, { color: "red" }));
}
return context.canvas;
});
}
}