an.ir.camera#

Camera semantics: the named moves, and the one resolver that expands them.

This module exists because the alternative was two hand-maintained tables. The compiler owned CAMERA_MOVES and an.ir.validate owned a frozenset of the same names, reconciled by a test — which works, and is not what “a move that validates cannot then raise” means. It means one table.

It lives under an/ir/ rather than in the cutout adapter because the IR layer must not import an adapter, and validate is in the IR layer. The camera is IR semantics anyway: Camera/CameraKey are schema models, and a renderer that cannot honour a move says so through can_render, not by keeping its own vocabulary.

The geometry it encodes, verified numerically against the vendored PixiJS composition: root.pivot IS a 2D camera, because PixiJS composes world = position + M·(local − pivot) and the runtime indexes the centre container as root. +x moves the CAMERA right, which moves content left.

Module Attributes

PAN_FRACTION

How far a pan travels, as a fraction of the canvas width (a tilt uses the same fraction of the height).

DOLLY_IN

How far the named dollies travel (an#478), as CameraKey.dolly.

CAMERA_MOVES

The named moves, as KEY LISTS.

FOLLOW_OVERLAY_FIELDS

how far the camera travels in and its zoom.

Functions

camera_keys(shot, *, width, height)

The shot's camera as an explicit key list — the ONE resolver.

camera_shake_offsets(shot, *, width, height)

The shot's camera shakes as (time, dx, dy) screen offsets — the ONE resolver (an#429).

dolly_frames(keys, *, duration, fps[, ...])

keys as one key per instant of the camera sampler when any of them dollies (an#478), else keys unchanged (and a single key, which is no move, as a single zoom key is not).

dolly_growth(factor, dolly)

How much a plane of parallax factor grows when the camera has travelled dolly (an#478): a pinhole camera, the plane at distance 1 / factor in units of the character plane's.

follow_overlay(keys, times)

(zoom, dolly) of a follow's key overlay at each of times (an#625), each field by the keys' own easings; (1.0, 0.0) with no overlay.

frame_times(duration, *, fps)

The time of every frame a duration render draws, the end included (k / fps, the renderer's own expression, capped at duration).

is_affine(keys)

Whether the frame keys show is checkable at the keys alone (an#626).

plane_dolly_scale(factor, dolly, *[, plane])

The scale a plane of parallax factor takes ON TOP of the root's zoom when the camera has travelled dolly (an#478): its growth over the character plane's, (1 − dolly) / (1 − factor · dolly).

sample_camera(keys, grid)

keys evaluated at every instant of grid (an#626), one key each with the grid's easing: every field by the keys' own easings, the zoom multiplied by the character plane's dolly growth (exactly 1 without a dolly), so the root zooms as a pinhole camera does.

Exceptions

CameraError

A camera that cannot be resolved into keys.

an.ir.camera.CAMERA_MOVES: dict[str, Callable[[float], list[CameraKey]]] = {'dolly_in': <function <lambda>>, 'dolly_out': <function <lambda>>, 'hold': <function <lambda>>, 'pan_left': <function <lambda>>, 'pan_right': <function <lambda>>, 'pull_out': <function <lambda>>, 'push_in': <function <lambda>>, 'tilt_down': <function <lambda>>, 'tilt_up': <function <lambda>>, 'zoom_in': <function <lambda>>, 'zoom_out': <function <lambda>>}#

The named moves, as KEY LISTS. move is sugar over keys — one code path, two front doors.

The five zoom moves must desugar to exactly the document they produced before an#109, which is more specific than “a scale tween”: two animations named __camera__<shot>_scale_x/_scale_y, one channel each targeting root, keyframes [(0.0, s0, "ease_in_out"), (duration, s1, null)], on two tracks rooted at "__camera__", and no pivot channels. The emitter emits only the channels that actually vary, which is what makes that true rather than merely intended — and what keeps every camera scene’s contract hash where it was.

exception an.ir.camera.CameraError[source]#

Bases: ValueError

A camera that cannot be resolved into keys.

A plain ValueError subclass so the IR layer can raise it without knowing about any renderer; the cutout compiler re-raises it as a CutoutCompileError at its own boundary.

an.ir.camera.DOLLY_IN: float = 0.2#

How far the named dollies travel (an#478), as CameraKey.dolly. Chosen so the character plane grows as under push_in (×1.25) and pull_out (×0.8): dolly_in is push_in with depth, a foreground plane at depth 1.4 growing ×1.39 and a moon at 0.08 ×1.02 (the design of record’s numbers).

an.ir.camera.FOLLOW_OVERLAY_FIELDS: frozenset[str] = frozenset({'at', 'dolly', 'easing', 'zoom'})#

how far the camera travels in and its zoom. Its position is the follow’s, and a roll would turn the frame the follow holds the target in.

Type:

What a follow’s key overlay may set (an#625)

an.ir.camera.PAN_FRACTION: float = 0.3333333333333333#

How far a pan travels, as a fraction of the canvas width (a tilt uses the same fraction of the height). A third of the frame is a legible move at any resolution and is the one number a named pan has to choose; an author who wants a different distance writes keys and says so.

an.ir.camera.camera_keys(shot, *, width, height)[source]#

The shot’s camera as an explicit key list — the ONE resolver.

move and keys are two front doors on one path. **Validate calls this and so does the compiler**, which is what makes “a move that validates cannot then raise” true by construction rather than by two tables agreeing — the arrangement it replaced (an#109 review, H-1).

>>> from an.ir.schema import Camera, Shot
>>> push = Shot(id="s", renderer="cutout", duration=2.0, camera=Camera(move="push_in"))
>>> [(k.at, k.zoom) for k in camera_keys(push, width=320, height=240)]
[(0.0, 1.0), (2.0, 1.25)]
>>> pan = Shot(id="s", renderer="cutout", duration=2.0, camera=Camera(move="pan_left"))
>>> [(k.at, round(k.x, 3)) for k in camera_keys(pan, width=320, height=240)]
[(0.0, 0.0), (2.0, -106.667)]
Return type:

list[CameraKey]

an.ir.camera.camera_shake_offsets(shot, *, width, height)[source]#

The shot’s camera shakes as (time, dx, dy) screen offsets — the ONE resolver (an#429).

Empty when the shot has none. Each shake is at rest (0, 0) at its start and its end; between, the frame jumps frequency times a second to a seeded offset of at most amplitude × the frame height, scaled down linearly to rest when decay. Validate and the compiler both call this, so a shake that validates cannot then raise (as with camera_keys()).

>>> from an.ir.schema import Camera, CameraShake, Shot
>>> s = Shot(id="s", duration=2.0, camera=Camera(shake=[CameraShake(at=1.0, duration=0.25, frequency=8)]))
>>> [(t, round(dx, 2), round(dy, 2)) for t, dx, dy in camera_shake_offsets(s, width=1280, height=720)]
[(1.0, 0.0, 0.0), (1.125, 3.72, 2.79), (1.25, 0.0, 0.0)]
Return type:

list[tuple[float, float, float]]

an.ir.camera.dolly_frames(keys, *, duration, fps, step_hz=None, frame_samples=None, sample_fps=None)[source]#

keys as one key per instant of the camera sampler when any of them dollies (an#478), else keys unchanged (and a single key, which is no move, as a single zoom key is not).

A dolly’s growth is not linear in its travel, so a key list that eases dolly cannot be eased in zoom too: each key is the camera evaluated there (sample_camera()), at every instant of an.frame_clock.camera_grid() — every frame, every step of a stepped shot (step-eased, so a step is a cut), and every instant the render samples (frame_samples, a shutter’s sub-frame ones, an#626) — so it is exact wherever the render looks.

>>> frames = dolly_frames(CAMERA_MOVES["dolly_in"](1.0), duration=1.0, fps=4)
>>> [(k.at, round(k.zoom, 3), round(k.dolly, 3)) for k in frames][::2]
[(0.0, 1.0, 0.0), (0.5, 1.111, 0.1), (1.0, 1.25, 0.2)]
>>> samples = [[0.0, 0.1], [0.25], [0.5], [0.75]]  # one entry per frame
>>> shutter = dolly_frames(CAMERA_MOVES["dolly_in"](1.0), duration=1.0, fps=4, frame_samples=samples)
>>> [k.at for k in shutter][:3]
[0.0, 0.1, 0.25]
Return type:

list[CameraKey]

an.ir.camera.dolly_growth(factor, dolly)[source]#

How much a plane of parallax factor grows when the camera has travelled dolly (an#478): a pinhole camera, the plane at distance 1 / factor in units of the character plane’s.

>>> dolly_growth(1.0, 0.2), round(dolly_growth(1.4, 0.2), 3), dolly_growth(0.0, 0.2)
(1.25, 1.389, 1.0)
Return type:

float

an.ir.camera.follow_overlay(keys, times)[source]#

(zoom, dolly) of a follow’s key overlay at each of times (an#625), each field by the keys’ own easings; (1.0, 0.0) with no overlay.

>>> follow_overlay([CameraKey(at=0.0), CameraKey(at=1.0, dolly=0.2)], [0.0, 1.0])
[(1.0, 0.0), (1.0, 0.2)]
>>> follow_overlay(None, [0.0, 0.5])
[(1.0, 0.0), (1.0, 0.0)]
Return type:

list[tuple[float, float]]

an.ir.camera.frame_times(duration, *, fps)[source]#

The time of every frame a duration render draws, the end included (k / fps, the renderer’s own expression, capped at duration).

THE frame grid rule (an#626). an.ir.camera.frame_times is this very function re-exported, and an.stage.solve.frame_times a thin wrapper over grid_times(); neither restates it.

>>> frame_times(0.5, fps=4)
[0.0, 0.25, 0.5]
Return type:

list[float]

an.ir.camera.is_affine(keys)[source]#

Whether the frame keys show is checkable at the keys alone (an#626).

Between two keys x, y and zoom share one eased parameter, and a plane edge minus a frame edge is then a linear term plus ±canvas/(2·zoom), convex in it, so its worst is at a key. Two things break that: a DOLLY (a plane grows by 1/(1 − f·dolly), an#478) and a ROLL that changes between keys (the rolled frame’s extent goes by the cosine and sine of the angle). A constant roll is affine; so is a single key. A follow is never affine (its keys are where its target goes), and has no authored keys to ask about but its overlay.

>>> is_affine([CameraKey(at=0.0), CameraKey(at=1.0, x=40.0, zoom=1.5)])
True
>>> is_affine([CameraKey(at=0.0), CameraKey(at=1.0, dolly=0.2)])
False
>>> is_affine([CameraKey(at=0.0), CameraKey(at=1.0, rotation=0.3)])
False
>>> is_affine([CameraKey(at=0.0, rotation=0.3), CameraKey(at=1.0, rotation=0.3, x=9.0)])
True
Return type:

bool

an.ir.camera.plane_dolly_scale(factor, dolly, *, plane='')[source]#

The scale a plane of parallax factor takes ON TOP of the root’s zoom when the camera has travelled dolly (an#478): its growth over the character plane’s, (1 − dolly) / (1 − factor · dolly). Exactly 1.0 without a dolly or at factor 1. A dolly that reaches the plane (the camera at or past it) is a CameraError.

>>> plane_dolly_scale(1.0, 0.2), plane_dolly_scale(0.0, 0.0), round(plane_dolly_scale(0.0, 0.2), 3)
(1.0, 1.0, 0.8)
Return type:

float

an.ir.camera.sample_camera(keys, grid)[source]#

keys evaluated at every instant of grid (an#626), one key each with the grid’s easing: every field by the keys’ own easings, the zoom multiplied by the character plane’s dolly growth (exactly 1 without a dolly), so the root zooms as a pinhole camera does.

>>> from an.frame_clock import camera_grid
>>> keys = [CameraKey(at=0.0), CameraKey(at=1.0, rotation=0.4)]
>>> [(k.at, round(k.rotation, 2), k.easing) for k in sample_camera(keys, camera_grid(1.0, fps=2))]
[(0.0, 0.0, 'linear'), (0.5, 0.2, 'linear'), (1.0, 0.4, 'linear')]
Return type:

list[CameraKey]