Published
Edited
Mar 18, 2021
1 fork
Importers
10 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
timer = new Timer({
duration: 4,
currentTime: 1,
autoplay: false,
loop: true,
playbackRate: 0.5,
defaultPlaybackRate: 1.,
delay: 200
})
Insert cell
viewof currentTime = videoControls(timer)
Insert cell
Insert cell
Insert cell
Insert cell
timer2 = {
const timer = new Timer();
timer.currentTime = 0.1;
timer.loop = true;
return timer;
}
Insert cell
Insert cell
timer2.duration
Insert cell
timer2.currentTime
Insert cell
timer2.paused
Insert cell
Insert cell
{
let loops = 0;
const div = html``;
function update() {
div.innerHTML = `The timer has looped <strong>${loops} times since the page has loaded</strong>.`;
}
function count() {
loops += 1;
update();
}
timer2.addEventListener('ended', count);
invalidation.then(() => timer2.removeEventListener('ended', count));
update();
timer2.play();
return div;
}
Insert cell
Insert cell
timer3 = new Timer({ duration: 10, autoplay: true, loop: true, delay: 1000 })
Insert cell
Insert cell
animation(timer3)
Insert cell
function animation(timer) {
const height = 33;
const radius = height / 2 - 5;
const context = DOM.context2d(width, height);
let frame;

(function tick() {
const x =
((Math.sin(timer3.currentTime) + 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
Insert cell
Insert cell
Insert cell
Insert cell
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