Write an animation once in Python.
Get a GIF, a WebP, an MP4 and an animated SVG, and they all look the same.
y points up, type size in points
ck.Scene(duration=5, size=(9, 9))positions, colours, opacity, even text
Circ(lambda t: (1 + t, 4.5), r=lambda t: 0.2 + 0.04 * t,
fill=ck.keyframes({0: "#0f9d8a", 7: "#e17d38"}))
Txt(lambda t: f"{int(100 * t / 7)} %", (4.5, 2.4), 56)polygon, line, circle, text, image
Poly Path Circ Txt Imgno seams, smaller SVGs
with scene.group("step1", ck.fade(0, 3.2)): ...
with scene.group("step2", (3.2, 6.0)): ...add an intro or reading pauses later
ck.Scene(duration=6, intro=1.2, holds={3: 1.6})import numpy as np
import cardkit as ck
from cardkit import Txt, Path, Circ, ramp
scene = ck.Scene(duration=4, size=(10, 6))
p = ramp(0.8, 2.6) # 0 -> 1 between 0.8 s and 2.6 s
# a title fades in, a curve draws itself
scene.add(Txt("Hello, cardkit", (0.7, 5), 30, op=ramp(0.2, 0.8)))
x = np.linspace(0.8, 9.2, 120)
scene.add(Path(np.c_[x, 2.6 + 0.9 * np.sin(1.6 * x)],
"#0f9d8a", 4, draw=p))
# a counter, and a dot that pulses forever
scene.add(Txt(lambda t: f"{100 * p(t):.0f} %", (0.7, 0.9), 22))
scene.add(Circ((9, 5.1), r=ck.pulse(1.2, 0.1, 0.2), fill="#0f9d8a"))
scene.save_all("out/hello", "gif", "svg")
<img>The BrainPFN card: 25 s, four steps, an intro and four pauses.
scene = ck.Scene(duration=25, size=(9, 11.25), origin=(0, -0.85), intro=3.0,
holds={6.05: 0.9, 11.85: 0.9, 17.65: 0.9, 24.65: 0.9})
# ... an intro and four groups: connectivity, mechanisms, meta-training, results
scene.storyboard("board.png", labels=True, cols=6, keys=[
("hook", -1.3), ("connectivity", 3.8), ("small N", 5.9),
("mechanisms", 11.7), ("meta-training", 17.6), ("results", 24.6)])
scene.check_text(scene.to_display(24.6)) # [check t=30.30] 45 texts, 0 issues
check_text flags overlapping or clipped labelsfrom cardkit.three import Camera, box, slab
cam = Camera(origin=(0.5, 3.4)) # fixed oblique camera
# a (5, 5) matrix lies flat, revealed cell by cell
scene.add(slab(cam, (0, 0, 0), fc, 0.6,
colors=lambda v: ck.mix("#fff", "#0f9d8a", abs(v)),
reveal=lambda k: ramp(0.3 + 0.03 * k, 0.6 + 0.03 * k)))
# boxes whose height is a function of time
for k, h in enumerate([1.6, 2.6, 2.0, 3.2]):
z = ramp(1.5 + 0.3 * k, 2.5 + 0.3 * k) * h
scene.add(box(cam, (4.2 + 0.9 * k, 0.4, 0), (0.7, 0.7, z),
"#6c5ce7"))
Plain polygons, Lambert lighting, hidden faces removed once: the animated SVG stays fully vector.