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

const n = 92; // must be even
const points = [];
for (let i = 0; i < n; ++i) {
const p = coordsFromDeg(i * (360 / n), 300);
points.push(p);
}

const lines = [];
const times = [];
const signs = [];
for (let i = 0; i < n / 2; ++i) {
const l = [points[i], points[n / 2 + i]];
times.push(0);
signs.push(1);
lines.push(l);
}

yield context.canvas;
let numL = 0;
let t = 0;
while (true) {
await Promises.delay(10);
context.clearRect(-width / 2, -height / 2, width, height);

for (let i = 0; i <= numL; ++i) {
line(...lines[i], context, { color: 'rgba(100,100,100,0.3)' });
const q = pointOnLine(lines[i], times[i]);
circle([...q, 3], context);
times[i] += signs[i] * 0.0033;
if (times[i] < 0 || times[i] > 1) signs[i] *= -1;
}

if (numL < lines.length - 1 && t % 20 === 19) {
numL++;
}

t++;
}
}
Insert cell
height = width / 1.5
Insert cell
import { circle, line, pointOnLine, coordsFromDeg } from '@timhau/geometry'
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more