Public
Edited
Dec 17, 2021
Insert cell
Insert cell
viewof gif = {
const gif = new GIF();
const canvas = DOM.canvas(width, height);
const context = canvas.getContext("2d");
context.font = "120px Helvetica Neue";
context.textAlign = "center";
let input = "1".repeat(7) + "33";
for (let i = 0, n = 25; i < n; ++i) {
context.clearRect(0, 0, width, height);
context.fillStyle = `hsl(${(i / n) * 360},100%,50%)`;
context.fillText(input, width / 2, height / 2 + 40);
gif.addFrame(canvas, { copy: true, delay: 500 });
input = editorStep(input);
yield canvas;
}
canvas.value = new Promise((resolve) => gif.on("finished", resolve));
gif.render();
yield canvas;
}
Insert cell
editor = html`<img src="${URL.createObjectURL(gif, { type: "image/gif" })}">`
Insert cell
DOM.download(gif, editor.gif, "Скачать")
Insert cell
GIF = {
const [gif, workerScript] = await Promise.all([
require("gif.js@0.2"),
require.resolve("gif.js@0.2/dist/gif.worker.js")
.then(fetch)
.then(response => response.blob())
.then(blob => URL.createObjectURL(blob, {type: "text/javascript"}))
]);
return class extends gif {
constructor(options) {
super({workerScript, ...options});
}
};
}
Insert cell
width = 640
Insert cell
height = 200
Insert cell
editorStep = function (s) {
let str = s;
if (/12|13/g.test(str)) {
str = str.replace(/12/, "21");
str = str.replace(/31/, "23");
str = str.replace(/13/, "23");
}
return str;
}
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