Core animation concepts
An animation is a timeline of entity properties. The Python builder creates that timeline; a renderer evaluates it at a requested frame. Build-time reads reflect the current builder context, not the viewer's playback position.
A video and its entities
Video2d(build, resolution=(640, 360), fps=30) calls the
callback with a SequenceBuilder and a root visual Frame. Construct entities
with a parent: Rectangle(frame, Position(40, 60), Position(120, 50)) adds a shape
to the root. Group(frame) supplies a shared transform for several children.
Construction order contributes to generated entity IDs. Let the library assign IDs; use IDs returned by the inspection API for selecting compiled entities. Moving a component between sequences may change its identity.
Coordinates and transforms
Positive x points right; positive y points down. A child position is relative to
its parent. Root units are pixels. A grid's child units are cells: its scale
property converts cell coordinates to parent coordinates.
position inherits the parent's origin and coordinate scale. opacity multiplies
through the hierarchy. visual_scale, rotation, and pivot transform a rendered
subtree; rotation is in radians. resolution follows the parent when omitted.
Shapes expose geometry such as size, radius, or path commands, plus fill,
stroke, stroke_width, and paint opacity. A None fill/stroke disables it.
RGB colors use channels from 0 through 255.
A component extends EntityWithChildren, supplies container properties, declares
a renderer-compatible kind, and creates its primitive children under itself.
Use kind = 'group' when the component needs no special rendering. Custom kinds
still need the renderer to understand the resulting primitive structure.
Property targets and values
Use an uncalled property to schedule a change, call it to read the local value,
and call resolve() to include inherited values at the current builder position.
position = box.props.position() # current local snapshot
world_position = box.props.position.resolve() # include parent inheritance
box.props.position = Position(80, 60) # instantaneous authored change
seq.show(SetProperty(box.props.opacity, 0)) # schedule a target, not a value read
Assign complete values. Mutating a returned snapshot does not update the timeline.
Property names must already exist. Register component defaults with
MyComponent.defineProp('amount', 0) before constructing the first instance;
registration after instantiation raises an error. Package register() hooks run
before Video2d constructs entities.
Inheritance rules declare their inputs with InheritanceInput and combine them
with supported arithmetic in Inheritance. Use the expression-aware vector,
sin, and cos helpers. Python branching on traced inputs is unsupported.
Time and composition
Numeric durations are seconds. seq.show(0.5) holds for half a second;
seq.show(a, b) runs animations concurrently. Sequence(a, b) runs them in order,
whereas Bundle(a, b) starts both together and lasts as long as its longest child.
Delay(seconds, animation) adds an initial hold. Repeat(animation, times=3)
plays three consecutive copies. The count must be a nonnegative integer, and
a count of zero produces an empty timeline.
Move adds a local displacement. MoveTo targets an absolute local position.
RelativeTransition adds a value; AbsoluteTransition targets a value. Default
motion uses smoothstep interpolation; fades default to linear. Durations must be
nonnegative. Avoid overlapping writes to the same property.
FadeIn normally sets opacity to zero when it is constructed. Construct reveal
animations before preceding holds or introductions when objects should begin
hidden. Use zero_opacity=False to preserve the existing starting opacity.
For frame-based time, import Frame from codeanimate.sequence.time under an
alias such as FrameTime to avoid confusing it with the visual root Frame.
FrameTime(30, 15) represents half a second. TimeMap converts between time
formats; seconds-to-frames rounds to the nearest frame, and changing a frame rate
rounds down. Frame counts include the timeline endpoint.
Text and fonts
TextGrid lays out characters in cells. insert() returns created Character
entities, advances the cursor, and treats spaces as cursor movement without new
entities. Newlines reset x and advance y. Use grid.line(index), cols(start, end),
or Python regex queries to select characters. Row/column interval methods include
both endpoints; range(start, end) excludes the end cell.
Font('Source Code Pro') selects a font family from your project's available
fonts. Use weight and style to select a face, for example
Font('Source Code Pro', weight=700). Add font files and configure their faces
in project.json before using them. A missing face produces an error naming the
requested font. ScaleFont changes both character size and grid cell metrics.
Choosing an extension
Use an ordinary component when primitive children are enough. Compose existing
animations before implementing Animation.timeline() yourself. Use a renderer
plugin only when an effect requires browser-side drawing. A renderer plugin must
support arbitrary frame order so preview seeking and export agree.
Project imports
The library supplies the top-level manifest package. Import core symbols with
from manifest import Video2d, Rectangle, colors and package classes with
from manifest.chart import LineChart. No project-local manifest.py is needed.
Importing the namespace loads project.json and activates all selected Python
plugins and dependencies. Video2d automatically uses that loaded manifest.
from manifest import project exposes the underlying Video2dManifest for helpers
that require it explicitly; assets and data expose asset and data-source access.
Define builders at module scope and create fresh entity instances inside them. Module-level component classes and imported functions are reusable; scene objects belong to a particular frame and sequence stack. This import convention does not make functions pure or implement caching: configuration, imported packages, assets, and data results remain build dependencies.
Managed compilers use codeanimate.project_context.project_context(path) to scope
imports to one project.json and restore the previous namespace on exit. Standalone
imports find project.json in the current working directory. Run from the project
directory and supply additional package roots with CODEANIMATE_PACKAGE_PATH.
The explicit Video2dManifest API remains available for standalone integrations.
Python module registries and property registration are process-wide; concurrent
compilations and builds requiring isolated core registrations use separate processes.
Project font families
A project's fonts object maps selected family names to explicit static faces:
{"fonts": {"JetBrains Mono": [
{"path": "assets/fonts/JetBrainsMono-Regular.ttf", "weight": 400, "style": "normal"}
]}}
Font("JetBrains Mono", weight=400, style="normal") requests that exact face.
Include additional files to enable other weights and styles. The manifest checks
file metadata and confines paths to project assets; project font resolution never
searches system fonts or substitutes another face. Unsupported characters produce
an error, including characters introduced by animation. Static TTF and OTF files
are supported; variable fonts and font collections are not.
For projects declaring fonts, TextGrid defaults to JetBrains Mono Regular
when registered, otherwise registered Source Code Pro Regular for migrated
projects. If neither face is selected, pass an explicit font=Font(...).
An empty fonts object deliberately enables no fonts.
Older projects without this field retain their host registry and Source Code Pro
default until migrated. Saved project font files should travel with project.json.
Motion paths
MoveAlong(entity, MotionPath.arc(center=(200, 200), radius=100,
start_angle=0, sweep_angle=1.5707963267948966), time=2) moves along an exact circular
arc. Angles are radians, positive clockwise. MotionPath.from_commands accepts
one absolute M/L/Q/C/Z contour; MotionPath.from_svg_path also supports SVG syntax
and the existing cubic approximation of SVG elliptical arcs.
Paths are immutable geometry, independent of drawable Path entities. Relative
movement (the default) anchors the first path point at the scheduled starting
position; relative=False uses absolute parent coordinates. The endpoint becomes
the authored position for subsequent animations. Linear interpolation gives
constant local-coordinate speed; smoothstep eases once over the whole route.
Parent transforms still apply normally. Geometry and orientation are not animated
by the path itself.
The DOM stores two movement keys and compact geometry under options.motion.
Full circles move even though both key values are equal. No per-frame samples are
serialized. Python consumers should use codeanimate.video2d.dom_resolution for
Video2D documents: prepare_document(document) prepares a reusable index and
ResolvedScene(prepared, frame) evaluates arbitrary frames without rebuilding
geometry. The generic sequence resolver remains independent of Video2D.