Core Architecture & Design Principles¶
handanim is built around a clean, stateless vector pipeline that separates geometry generation from timeline evaluation and backend rendering.
The Four-Stage Pipeline¶
Drawable (Immutable)
│ .draw()
▼
OpsSet (Vector Operations: MOVE_TO, LINE_TO, CURVE_TO, SET_PEN, ...)
│ AnimationEvent.apply(opsset, progress)
▼
Animated Frame OpsSet (World Ops + Camera-Invariant Overlay Ops)
│ Viewport transform
▼
Backend Renderer (Cairo PNG/MP4/SVG/PDF or Native LaTeX TikZ)
1. Immutable Drawable Objects¶
Every shape, text block, math formula, or character rig inherits from Drawable.
Calling
drawable.draw()deterministically compiles the primitive into anOpsSet—a flat list of low-level vector instructions (Ops).Calling
drawable.translate(dx, dy),drawable.scale(sx, sy),drawable.rotate(deg), ordrawable.center_at(x, y)wraps the original drawable in aTransformedDrawablewithout mutating the original object.DrawableCachecaches the baseOpsSetof each drawable by ID sodraw()is only computed once per scene.
2. Vector Ops and OpsSet¶
An OpsSet is a sequence of Ops records. Each operation has:
type(OpsType):SET_PEN,MOVE_TO,LINE_TO,CURVE_TO,QUAD_CURVE_TO,CLOSE_PATH,DOT,IMAGE,PUSH_CLIP, orPOP_CLIP.data: Coordinate tuples, polygon clip vertices, or pen styling dicts (color,width,opacity,fill).partial(floatin[0, 1]): Used bySketchAnimationto slice cubic Bézier curves and line segments mid-stroke.meta(dict): Metadata tags for group filtering, base opacity tracking, and overlay layer routing.
3. Stateless AnimationEvent Transformations¶
Every animation (SketchAnimation, FadeInAnimation, TranslateFromAnimation, PoseAnimation, etc.) is a pure function:
where raw_progress is mapped through event.easing_fun (if provided) before computing the transformed OpsSet.
Events are categorized into three lifecycle types (AnimationEventType):
CREATION(e.g.,SketchAnimation,FadeInAnimation,PopAnimation,Show): Makes the object visible on the timeline starting atstart_time.MUTATION(e.g.,TranslateToAnimation,RotateAnimation,ColorTransitionAnimation,PoseAnimation): Modifies an active object betweenstart_timeandend_time.DELETION(e.g.,FadeOutAnimation,Hide): Deactivates the object atend_time.
4. Two-Layer Viewport Rendering (World vs. Overlay)¶
During frame rendering, Scene partitions each frame’s operations into two layers:
World Layer (
scene.add(...)): Rendered throughscene._get_viewport_at(t), which interpolates any activeCameraAnimationpan/zoom events. When aSceneTransition(PageTurnTransitionorPaperCrumpleTransition) is active, world objects are automatically partitioned into outgoing-page and incoming-pageOpsSet``s, composed with polygonal clipping (``PUSH_CLIP/POP_CLIP) and geometric warping, and outgoing-page objects are deactivated oncetransition.end_timeis reached.Overlay Layer (
scene.overlay.add(...)): Rendered afterward through the static basescene.viewport, keeping HUD elements, watermarks, and word-timedCaptionspinned on screen regardless of camera movement or page transitions.