kinemo API reference
kinemo 0.9.0 (IR 1.0.0). Every name in kinemo.__all__ and every public method of a public class, with signatures, parameters, props and canonical examples. Examples start with import kinemo as k and pass kinemo check --strict.
Also: Diagnostics, Command line, Configuration.
Scene#
Scenes, the timeline cursor and the blocks that shape time (s.play, s.start, s.during).
k.scene: Turns a functiondef name(s: k.Scene)into a scene.k.SceneDef: A scene function plus its configuration.k.Scene: Timeline of one scene.k.TimeSpan: Where aplay/startlanded.k.time: Global scene time in seconds, as a read-only signal.
Methods:
s.play: Schedules animations at the cursor and advances the cursor to their end.s.start: Schedules animations at the cursor without moving it: this is how to run something in the background (clocks, simulations, continuous motion) while the script continues.s.wait: Advances the cursor bydseconds (default 1).s.wait_for: Moves the main cursor to the time of an event (thecount-th firing after the cursor) and returns theEventInfo.s.add: Puts objects in the scene instantly, at the cursor.s.remove: Takes objects out of the scene instantly, at the cursor.s.mark: Creates a time anchor at the cursor without moving it and returns the time.s.during:withblock that applies state changes on entry and reverts them, animated, on exit.s.tempo:withblock that multiplies the speed of everything inside:s.tempo(4)divides durations and waits by 4.s.voice: Narratedwithblock: takes text (TTS from the provider inkinemo.toml) or an audio file, and lasts at least as long as the audio.
Object state#
Changing objects: animated state changes (.to()), instant writes (.set()), copies.
k.Node: Objects are values: creating one does not put it in the scene (uses.addor a verb).k.reparent: Moves an object to another group at the scheduled time, keeping its world position (inside a container, it takes its place in the flow).
Methods:
obj.to: Animated state change: interpolates each prop from its value at the cursor to the target.obj.set: Instant change at the cursor.obj.unbind: Removes reactive bindings (all props when no name is given), keeping the current value.obj.copy: Creates a new identity with the same props.
Verbs#
Entrance, exit and emphasis animations (k.draw, k.fade_out, k.indicate, k.morph).
k.draw: Entrance verb: traces the outline and then fills it.k.write: Entrance verb: writes the text character by character.k.fade_in: Entrance verb: opacity from 0 to 1.k.fade_out: Exit verb: opacity from 1 to 0, and then the objects leave the scene.k.grow: Entrance verb: scales up from the center (default) or from a side (from_="bottom","left","top-left"...).k.shrink: Exit verb: the inverse ofk.grow.k.indicate: Emphasis: temporarily tints and pulses the object; the final state equals the initial one.k.flash: Emphasis: a ring of light that expands from the object's edge and fades away.k.squash: Emphasis: an elastic squash against the object's base;amount=controls the intensity.k.follow: Motion: the object travels along a path (the outline of another object or a list of points, in world coordinates).k.sound: Audio: plays a sound file at the moment it is scheduled (zero duration in the script).k.morph: Swap:aleaves,benters and the matching parts travel between them (identical characters and tokens slide; the rest fades out and in).
Composition#
Combining animations in sequence, in parallel and with a lag; reusable clips; easing.
k.seq: Composes animations in sequence: each one starts when the previous one ends.k.par: Composes animations in parallel: they all start together and the group lasts as long as the longest one.k.stagger: Staggers a list of animations: each one startslagseconds after the previous one.k.clip: Decorator that turns a functiondef name(s: k.Scene, ...)into a reusable sequence with its own cursor.k.Animation: Immutable: only has an effect when passed tos.playors.start.k.ease: Easing curves.
Methods:
anim.with_: Returns a copy of the animation with a different duration, easing or delay.
Objects#
Shapes, groups, images, SVG and mass objects (points, vector fields, stream lines).
k.Circle: Circle of radiusr, centered on its position.k.Dot: Filled dot (default radius 0.08), with no stroke.k.Ellipse: Ellipse of widthwand heighth, centered on its position.k.Rect: Rectangle of widthwand heighth, centered on its position;radius=rounds the corners (for rounded corners preferk.RoundedRect).k.RoundedRect: Rectangle with rounded corners (radius=0.15by default).k.Square: Square with sideside, centered on its position.k.Polygon: Polygon from its vertices (k.Polygon((0, 0), (2, 0), (1, 1))), centered on its bounding box.k.Triangle: Triangle from its three vertices (no arguments: equilateral with radius 1).k.Line: Segment fromstarttoend(local coordinates), or centered withlength=.k.Arrow: Arrow fromstarttoendwith a tip of sizetip.k.Arc: Circular arc of radiusr, starting atstart_angleand sweepingangledegrees (counterclockwise).k.Path: Path from SVG commands (d="M 0 0 L 1 1") or a polyline from a list of points;closed=Truecloses the outline.k.union: Boolean operations between shapes:k.union(a, b),k.intersect(a, b)andk.subtract(a, b)return a newk.Pathcomputed from the outlines at the cursor (with the style ofa, unless another one is passed).k.intersect: Shape covering bothaandb.k.subtract:awithbcut out.k.Bar: A value shown as a bar that grows from its base, with an optional label (label=True).k.Group: Groups objects: transforms compose and opacity multiplies.k.Image: Raster image (PNG or JPEG) drawn by the renderer, centered on its position.k.SVG: Imports an SVG illustration (a file or inline markup): each shape becomes ak.Pathwith the SVG's fill, stroke and stroke width, and each<g>becomes ak.Group.k.Brace: Curly brace (}) along one side of an object's box:direction="down", "up", "left" or "right",gapunits away from it, with the tip pointing outward.k.Points: Thousands of points in a single object, batch-drawn in the core.k.VectorField: Arrows of a fieldfn(x, y) -> (vx, vy)on a grid withdensitycolumns across the width of the region (x_range,y_range).k.StreamLines: Streamlines of a field (ak.VectorFieldor a function), integrated with RK4 in the core fromseeds(a count or points).
Text#
Text, LaTeX math and highlighted code, with addressable parts.
k.Text: Text with minimal inline markup (**bold**,*italic*,`code`).k.Math: Formula in LaTeX syntax, typeset by the built-in engine (no TeX installation needed).k.Code: Code with syntax highlighting (tree-sitter) and stable tokens:lang=,line_numbers=True,size=,theme="auto"(follows the scene background).
Methods:
code.highlight: Named transition: dims every line exceptlines(numbered from 1);code.highlight(None)removes the highlight.
Layout#
Placement by constraints (.place) and containers (k.Row, k.Column, k.Grid, k.Stack).
k.Row: Container that lays its children out in a row (flexbox), withgap=andalign=("center","top","bottom").k.Column: Container that stacks its children in a column, withgap=andalign=("center","left","right").k.Grid: Grid container withcols=columns andgap=.k.Stack: Container that overlays its children, centered (or aligned byalign=).
Methods:
obj.place: Declares where the object sits, relative to the frame (at="top",margin=) or to another object (above=,below=,left_of=,right_of=,inside=withpad=), withgap=(accepts a signal) andalign=.obj.to_place: Animated change of placement: the.toof.place.obj.unpin: Releases the position constraint at the cursor: the object keeps its current position and is free to animatex/y.group.fit: Scales the group once, at the cursor, until it fits an area (usuallys.frame.safe, the frame's safe area), with an optionalmargin=.group.swap: Named transition: swaps the places of two children and the container animates the reflow.group.insert: Named transition: inserts a child at positioni; it enters together with the reflow.group.pop: Named transition: removes the child at positioni(default: the last one); it exits together with the reflow.
Charts#
Axes, number lines, polar axes, plots and data charts.
k.PolarAxes: Polar axes (rings and spokes):r=(0, r_max, step),radius=in units,spokes=.k.Axes: Cartesian axes with ticks, labels and an optional grid:x=(min, max, step),y=(min, max),labels=("x", "y"),width=/height=in units.k.NumberLine: A horizontal number line: ak.Axeswith only the x axis.Plot: A curvey = fn(x)of an axes.k.BarChart: Bar chart from a table:x=is the category column,y=the value column andkey=identifies each bar.k.LineChart: Ak.Axeswith one line pery=column (one or several), connecting the table's points inx=order.k.Table: Table ofk.Textwith a highlighted header;columns=selects and orders the columns.
Methods:
ax.parametric: Parametric curve(fx(t), fy(t))fort=(start, end); clipped to the visible ranges.ax.plot: Draws the curvey = fn(x)on the axes, with adaptive sampling.ax.area: Filled region under a curve (down to the x axis) or between two curves (between=).ax.vline: Vertical line on the axes atat=(accepts a signal: the line moves with it);style="dashed"makes it dashed.ax.hline: Horizontal line on the axes atat=(accepts a signal);style="dashed"makes it dashed.ax.scatter: Points(xs[i], ys[i])on the axes, as a group ofk.Dot.ax.zoom_to: Named transition: animates the visible ranges of the axes (x=(a, b),y=(c, d)).ax.point: Data point(x, y)in world coordinates, reactive whenxoryare signals.curve.point_at: World position of the curve atx; reactive whenxis a signal.curve.tangent_at: Tangent segmentlengthunits long, centered on the curve atx, reactive whenxis a signal.curve.slope_at: Numerical derivative of the curve atx, reactive whenxis a signal.
Reactive#
Signals, derived values and reactive collections.
k.signal: A value with a timeline.k.Signal: A value that changes over the timeline:.set(instant),.to(animated),.now.k.computed: Derived value with several dependencies:k.computed(lambda: f(a(), b())).k.Expr: A value that may change over time.k.list: List signal.k.ListSignal: Python lists are not tracked;k.list([...])is.k.python: Marks an opaque Python function (external libraries,math, untraceable logic).k.lerp: Interpolation modes of a signal, passed ask.signal(..., lerp=):linear(default),round(integers),step(switches at the end),step_start(switches at the start) andpointwise(lists of points, point by point).
Methods:
x.map: Applies a function to a signal:hour.map(solar_curve).
Native blocks#
Math blocks that run in the native core inside lambdas, .map and plots.
k.sin: Native math functions:k.sin,k.cos,k.tan,k.exp,k.log,k.sqrtandk.atan2(y, x).k.atan2: Native math functions:k.sin,k.cos,k.tan,k.exp,k.log,k.sqrtandk.atan2(y, x).k.cos: cos(x), native on signals.k.exp: exp(x), native on signals.k.log: ln(x), native on signals.k.sqrt: sqrt(x), native on signals.k.tan: tan(x), native on signals.k.floor: Native rounding down (k.floor) and up (k.ceil).k.ceil: ceil(x), native on signals.k.min: Native minimum and maximum of two or more values (k.min(a, b, c)).k.max: Native minimum and maximum of two or more values (k.min(a, b, c)).k.clamp: Clamps a value to the range[lo, hi], natively.k.where: The traceableif:awherecondholds, otherwiseb.k.piecewise: Piecewise function:k.piecewise((cond1, v1), (cond2, v2), default=v); the first true condition wins.k.spline: Smooth table interpolation (natural cubic spline):k.spline(x, xs, ys).k.interp: Linear table interpolation:k.interp(x, xs, ys).k.mix: Linear mixa + (b - a) * tof numbers, vectors or colors (colors in OKLab, with no gray in the middle).k.smoothstep: Smooth transition from 0 to 1 asxgoes frome0toe1(cubic Hermite).k.noise: Smooth, deterministic noise in [-1, 1] (seed=changes the sequence).k.vec: 2D vector from two values (numbers or signals).k.Vec: Vec(x, y)k.pi: Constantsk.pi,k.tau(2π) andk.e, for use inside traced functions.k.e: Constantsk.pi,k.tau(2π) andk.e, for use inside traced functions.k.tau: Constantsk.pi,k.tau(2π) andk.e, for use inside traced functions.
Stateful systems#
Conditions, integration and simulations resolved before rendering.
k.when: Edge-triggered effect: whencondgoes from false to true, it fires an animation or emits an event.k.integrate: Integral of an expression with respect to the change ind=(defaultk.time), starting at the cursor, withinitial=andclamp=(lo, hi).k.simulate: Fixed-step simulation:step(state, dt) -> state, run in Python during resolve.k.State: Base of simulation states: plain fields (floats, bools, pairs) plusk.Events. class Ball(k.State): y: float = 4.0 v: float = 0.0 bounce: k.Event[Impact]k.trace: Trail: the lastlengthseconds of the path of a moving point (usuallyobj.world.position), drawn as a stroke.k.Trail: Trail: the lastlengthseconds of the path of a moving point (usuallyobj.world.position), drawn as a stroke.
Events#
Event sources and handlers.
k.EventSource: A concrete event of one owner.k.EventInfo: One firing of an event, received by.onhandlers and returned bys.wait_for:e.time(instant),e.data(typed payload),e.count(n-th firing) ande.value(sig)(value of any signal at the instant of the event).
Methods:
event.on: Decorator that reacts to every firing of an event:@source.onregistersdef handler(s, e), run during resolve with its ownswhose cursor starts ate.time(the main cursor does not change).
Components#
Reusable components with props, outputs, events and context.
k.Component: The only kind of reusable object: a subclass with props (k.Prop[T], inputs), static fields (name: T = default), outs (k.Out[T], outputs as signals) and events (k.Event), plus abuild()that runs once and returns the visual.k.Prop: Declares a reactive component prop:power: k.Prop[float] = k.prop(0.0).k.Out: Declares a continuous component output:soc: k.Out[float].k.Event: Declares an event on a component or ak.State:full: k.Eventor, with a typed payload,bounce: k.Event[Impact].k.field: Validated default for a static component field:k.field(0.2, range=(0, 1))ork.field("a", choices=[...]).k.prop: Validated default for a reactive prop:k.prop(0.0, range=(-5, 5)).k.context: Declares a context (at module level): a value that many components need (clock, scale, unit), supplied withk.provideinstead of passed down prop by prop.k.Context:Clock = k.context("clock", default=k.time), declared at module level.k.provide:withblock that supplies a context value to the components constructed inside it.k.from_context: Prop or field default that reads a context:time: k.Prop[float] = k.from_context(Clock).
Parameters#
Scene parameters for the interactive player and exports.
k.Int: Integer scene parameter in the range[lo, hi]:k.Int(3, 12, default=5).k.Float: Real-valued scene parameter in the range[lo, hi]:k.Float(0.5, 2, default=1).k.Bool: Boolean scene parameter:k.Bool(default=True).k.Choice: Scene parameter with fixed options:k.Choice([k.BLUE, k.RED])(the default is the first option, ordefault=).k.Str: Text scene parameter:k.Str(default="...").
Output#
Movies made of several scenes and the transitions between them.
k.movie: Composes several scenes into a single output, with one transition per join (k.cutwhen omitted).k.Movie: Composes several scenes into a single output, with one transition per join (k.cutwhen omitted).k.cut: Hard-cut transition between two scenes of ak.movie(the default).k.crossfade: Transition in which the end of one scene dissolves into the start of the next, overdurationseconds.k.morph_cut: Transition in which objects with the samekey=in neighboring scenes travel across the cut.
Theme and colors#
Themes, theme tokens and colors.
k.theme: Tokens of the current theme:k.theme.bg,fg,accent,muted,secondary.k.themes: Built-in themes:k.themes.dark(default),k.themes.lightandk.themes.blueprint.k.Theme: Built-in themes:k.themes.dark(default),k.themes.lightandk.themes.blueprint.k.BLUE: Fixed palette:k.BLUE,k.RED,k.GREEN,k.YELLOW,k.ORANGE,k.PURPLE,k.PINK,k.TEAL,k.WHITE,k.BLACK,k.GRAYandk.TRANSPARENT.k.BLACK: Fixed palette:k.BLUE,k.RED,k.GREEN,k.YELLOW,k.ORANGE,k.PURPLE,k.PINK,k.TEAL,k.WHITE,k.BLACK,k.GRAYandk.TRANSPARENT.k.GRAY: Fixed palette:k.BLUE,k.RED,k.GREEN,k.YELLOW,k.ORANGE,k.PURPLE,k.PINK,k.TEAL,k.WHITE,k.BLACK,k.GRAYandk.TRANSPARENT.k.GREEN: Fixed palette:k.BLUE,k.RED,k.GREEN,k.YELLOW,k.ORANGE,k.PURPLE,k.PINK,k.TEAL,k.WHITE,k.BLACK,k.GRAYandk.TRANSPARENT.k.ORANGE: Fixed palette:k.BLUE,k.RED,k.GREEN,k.YELLOW,k.ORANGE,k.PURPLE,k.PINK,k.TEAL,k.WHITE,k.BLACK,k.GRAYandk.TRANSPARENT.k.PINK: Fixed palette:k.BLUE,k.RED,k.GREEN,k.YELLOW,k.ORANGE,k.PURPLE,k.PINK,k.TEAL,k.WHITE,k.BLACK,k.GRAYandk.TRANSPARENT.k.PURPLE: Fixed palette:k.BLUE,k.RED,k.GREEN,k.YELLOW,k.ORANGE,k.PURPLE,k.PINK,k.TEAL,k.WHITE,k.BLACK,k.GRAYandk.TRANSPARENT.k.RED: Fixed palette:k.BLUE,k.RED,k.GREEN,k.YELLOW,k.ORANGE,k.PURPLE,k.PINK,k.TEAL,k.WHITE,k.BLACK,k.GRAYandk.TRANSPARENT.k.TEAL: Fixed palette:k.BLUE,k.RED,k.GREEN,k.YELLOW,k.ORANGE,k.PURPLE,k.PINK,k.TEAL,k.WHITE,k.BLACK,k.GRAYandk.TRANSPARENT.k.TRANSPARENT: Fixed palette:k.BLUE,k.RED,k.GREEN,k.YELLOW,k.ORANGE,k.PURPLE,k.PINK,k.TEAL,k.WHITE,k.BLACK,k.GRAYandk.TRANSPARENT.k.WHITE: Fixed palette:k.BLUE,k.RED,k.GREEN,k.YELLOW,k.ORANGE,k.PURPLE,k.PINK,k.TEAL,k.WHITE,k.BLACK,k.GRAYandk.TRANSPARENT.k.YELLOW: Fixed palette:k.BLUE,k.RED,k.GREEN,k.YELLOW,k.ORANGE,k.PURPLE,k.PINK,k.TEAL,k.WHITE,k.BLACK,k.GRAYandk.TRANSPARENT.k.rgb: Color from components from 0 to 1 (a=is the opacity).k.Color: Color from components from 0 to 1 (a=is the opacity).
Tooling and types#
Names for tools and type annotations rather than scene code.
k.Diagnostic: Diagnostics are read withkinemo checkandkinemo explain <code>.k.IR_VERSION: IR format version, for tools.k.KinemoError: A build error.k.Val: Type alias T | Signal[T] | Callable[[], T], for annotations only.
Other pages#
- Diagnostics: Every error and lint code, grouped by range, with explanations and fixes.
- Command line: Every
kinemosubcommand with its arguments and examples. - Configuration:
kinemo.toml,@k.sceneoptions, sizes and quality presets.