Published
Edited
Oct 10, 2019
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
{
const context = DOM.context2d(width, width);
context.translate(width / 2, width / 2);

let angle = 0;
const trace = [];

yield context.canvas;

while (true) {
await Promises.delay(50);
context.clearRect(-width / 2, -width / 2, width, width);

const p1 = [x1 * (width / 2), y1 * (width / 2), 3];
circle(p1, context);
const l1 = lineThrough(p1, angle, context);

const p2 = [0.5 * (width / 2), -0.3 * (width / 2), 3];
circle(p2, context);
const l2 = lineThrough(p2, -angle, context);

const intersection = intersectionLL(l1, l2);
if (intersection) {
circle([...intersection, 3], context, { color: "red" });
trace.push(intersection);
}

if (trace.length > 150) trace.shift();

for (let p of trace) {
circle([...p, 3], context, { color: "red" });
}

angle = (angle + 1) % 360;
}
}
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more