vivant
Vivant
Vivant is a small Crystal shard for programmatic animations: draw each frame as SVG, pace the frames on a timeline, and render the result to a GIF. It was written to visualise Advent of Code solutions, where a simulation runs for hundreds of steps and you want the first few slow enough to follow, the middle as a blur, and the last few slow again.
The name
A tableau vivant ("living picture") is a staged scene brought to life, which is what this shard produces: you describe a scene, and it becomes a moving picture. tableau on its own was the first idea, but that name is thoroughly taken, so the shard is named after the other half.
Requirements
- Crystal 1.21 or newer
ffmpegbuilt with librsvg (check withffmpeg -decoders | grep librsvg)
Installation
The shard is not published yet, so depend on a local checkout in your shard.yml:
dependencies:
vivant:
path: ../vivant
Run shards install
Usage
require "vivant"
STEPS = 300
timeline = Vivant::Timeline.paced(STEPS, head: 5, tail: 3, blur: 7.0, hold: 1.5)
Vivant.render("countdown.gif", timeline) do |frame|
canvas = Vivant::Canvas.new(480, 160, background: "#111318")
x = Vivant.lerp(30, 450, (frame.step + Vivant.ease(frame.progress)) / STEPS)
canvas.line(30, 110, 450, 110, stroke: "#3a3f47", stroke_width: 2)
canvas.circle(x, 110, 9, fill: "#ffc53d")
canvas.text(30, 60, "step #{frame.step + 1} / #{STEPS}", size: 28, fill: "#e6e8eb")
canvas
end
There are three pieces:
Vivant::Canvasbuilds one frame:rect,circle,line,polygonandtext, drawn in call order.Vivant::Timelinesays how long each step of your simulation is on screen.Timeline.pacedgives the slow-blur-slow shape;Timeline.evengives every step the same time;Timeline.newtakes any list of per-step durations. EachFrameit produces carries thestepin progress and theprogress(0 to 1) through that step.Vivant.rendercalls your block once per frame and writes the animation. The format follows the extension:.gif, or anything else ffmpeg knows, such as.mp4.
Vivant.ease, Vivant.lerp and Vivant.phase help with motion inside a step.
Steps shorter than one frame are skipped rather than drawn, so your block must be able to draw any step directly instead of relying on having seen the previous one.
Development
Run tests with: crystal spec
License
Released under the MIT License. See LICENSE for details.
vivant
- 0
- 0
- 0
- 0
- 0
- about 2 hours ago
- December 2, 2026
MIT License
Wed, 02 Dec 2026 14:35:13 GMT