Published
Edited
Feb 15, 2021
6 forks
108 stars
Insert cell
Insert cell
Insert cell
{
const context = DOM.context2d(width, height);
let frame;
(function tick() {
const x = (Math.sin(Date.now() / 1000) + 1) / 2 * (width - 2 * radius) + radius;
context.clearRect(0, 0, width, height);
context.beginPath();
context.arc(x, height / 2, radius, 0, 2 * Math.PI);
context.fill();
frame = requestAnimationFrame(tick);
})();
invalidation.then(() => cancelAnimationFrame(frame));
return context.canvas;
}
Insert cell
Insert cell
Insert cell
{
const context = DOM.context2d(width, height);
while (true) {
const x = (Math.sin(Date.now() / 1000) + 1) / 2 * (width - 2 * radius) + radius;
context.clearRect(0, 0, width, height);
context.beginPath();
context.arc(x, height / 2, radius, 0, 2 * Math.PI);
context.fill();
yield context.canvas;
}
}
Insert cell
Insert cell
Insert cell
{
const context = DOM.context2d(width, height);
const x = (Math.sin(now / 1000) + 1) / 2 * (width - 2 * radius) + radius;
context.beginPath();
context.arc(x, height / 2, radius, 0, 2 * Math.PI);
context.fill();
return context.canvas;
}
Insert cell
Insert cell
Insert cell
{
const context = this ? this.getContext("2d") : DOM.context2d(width, height);
const x = (Math.sin(now / 1000) + 1) / 2 * (width - 2 * radius) + radius;
context.clearRect(0, 0, width, height);
context.beginPath();
context.arc(x, height / 2, radius, 0, 2 * Math.PI);
context.fill();
return context.canvas;
}
Insert cell
Insert cell
Insert cell
function* animate() {
while (true) {
yield Promises.tick(250, (Math.sin(Date.now() / 1000) + 1) / 2 * (width - 2 * radius) + radius);
}
}
Insert cell
{
const context = DOM.context2d(width, height);
for (const x of animate()) {
yield x.then(x => {
context.clearRect(0, 0, width, height);
context.beginPath();
context.arc(x, height / 2, radius, 0, 2 * Math.PI);
context.fill();
return context.canvas;
});
}
}
Insert cell
height = 33
Insert cell
radius = height / 2 - 5
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