Published
Edited
Sep 29, 2022
Importers
4 stars
Insert cell
Insert cell
Insert cell
timer(240)
Insert cell
timer(240, 2)
Insert cell
Insert cell
/**
* Generates timing parameters based on total frame and FPS
*
* @generator
* @param {number} [totalFrames=120] The total frames
* @param {number} [fps=60] The FPS
* @yields {object} The timer object: frame, playhead, totalFrames and FPS
*/
function* timer(totalFrames = 120, fps = 60) {
const step = fps / 60;
let frame = 0;

while (true) {
frame = frame < totalFrames ? frame + step : 0;
const frameFloor = Math.floor(frame);
const playhead = frameFloor / totalFrames;

yield {
frame: frameFloor,
fps,
totalFrames,
playhead
};
}
}
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