animate
animate("fn", frames, path, [fps=])
Input: "fn", frames, path, fps · Output: no output
What it is
Calls function "fn" (string) once per frame index from 0 to frames - 1 (integer) and writes the sequence to path (string) as one animated SVG, no JavaScript. fps= (number, default 24) sets playback speed.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
animate("fn", frames, path, [fps=]) | "fn" stringCalls function "fn" (string) once per frame index from 0 to frames - 1 (integer) and writes the sequence to path (string) as one animated SVG, no JavaScript.frames stringCalls function "fn" (string) once per frame index from 0 to frames - 1 (integer) and writes the sequence to path (string) as one animated SVG, no JavaScript.path stringCalls function "fn" (string) once per frame index from 0 to frames - 1 (integer) and writes the sequence to path (string) as one animated SVG, no JavaScript.fps number, optionalfps= (number, default 24) sets playback speed. | no output | — |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
function frame(i)
t = 2 * pi * i / 60
x = (0 to 200) / 20
plot(x, sin(x - t), color = "royalblue")
ylim(-1.2, 1.2)
axis off
end function
animate("frame", 60, "wave.svg", fps = 24)
not run by the build — this one needs something the repository cannot supply · from plotting
How it works
savefig(path, embed_fonts=true) — inline the actual font bytes (only possible for a curated fontfamily(...) preset) so the figure renders identically everywhere. Only the glyphs the figure actually draws are inlined (font_subset), so that costs tens of kilobytes rather than the whole font file. See Interp::save_figure. animate("draw", frames, "out.svg", fps = 24) — call a function you wrote once per frame, and write the sequence as one animated SVG. Why SVG and not GIF. A GIF needs an LZW encoder, caps the palette at 256 colours, and produces a raster that is wrong at any size but the one it was made at. An animated SVG is one file, opens in any browser, stays sharp at any size, and reuses the renderer that already exists -- the frames ARE ordinary Qu figures. How it animates without JavaScript. Each frame becomes a <g>, and each group carries a CSS animation that shows it for its own slot of the cycle and hides it otherwise. No SMIL (deprecated in places, unevenly supported) and no script, so the file works when opened from disk, embedded in a page, or dropped into a slide. The cost is size: a hundred frames is a hundred figures in one file. That is the honest trade, and the frame count is yours to choose.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.