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
How far a pan travels, as a fraction of the canvas width (a tilt uses the same fraction of the height). |
|
How far the named dollies travel (an#478), as |
|
The named moves, as KEY LISTS. |
|
how far the camera travels in and its zoom. |
Functions
|
The shot's camera as an explicit key list — the ONE resolver. |
|
The shot's camera shakes as |
|
|
|
How much a plane of parallax |
|
|
|
The time of every frame a |
|
Whether the frame |
|
The scale a plane of parallax |
|
|
Exceptions
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.
moveis sugar overkeys— 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 targetingroot, 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:
ValueErrorA camera that cannot be resolved into keys.
A plain
ValueErrorsubclass so the IR layer can raise it without knowing about any renderer; the cutout compiler re-raises it as aCutoutCompileErrorat 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 underpush_in(×1.25) andpull_out(×0.8):dolly_inispush_inwith 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
keysand says so.
- an.ir.camera.camera_keys(shot, *, width, height)[source]#
The shot’s camera as an explicit key list — the ONE resolver.
moveandkeysare 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)]
- 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 jumpsfrequencytimes a second to a seeded offset of at mostamplitude× the frame height, scaled down linearly to rest whendecay. Validate and the compiler both call this, so a shake that validates cannot then raise (as withcamera_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)]
- an.ir.camera.dolly_frames(keys, *, duration, fps, step_hz=None, frame_samples=None, sample_fps=None)[source]#
keysas one key per instant of the camera sampler when any of them dollies (an#478), elsekeysunchanged (and a single key, which is no move, as a singlezoomkey is not).A dolly’s growth is not linear in its travel, so a key list that eases
dollycannot be eased inzoomtoo: each key is the camera evaluated there (sample_camera()), at every instant ofan.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]
- an.ir.camera.dolly_growth(factor, dolly)[source]#
How much a plane of parallax
factorgrows when the camera has travelleddolly(an#478): a pinhole camera, the plane at distance1 / factorin 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:
- an.ir.camera.follow_overlay(keys, times)[source]#
(zoom, dolly)of a follow’s key overlay at each oftimes(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)]
- an.ir.camera.frame_times(duration, *, fps)[source]#
The time of every frame a
durationrender draws, the end included (k / fps, the renderer’s own expression, capped atduration).THE frame grid rule (an#626).
an.ir.camera.frame_timesis this very function re-exported, andan.stage.solve.frame_timesa thin wrapper overgrid_times(); neither restates it.>>> frame_times(0.5, fps=4) [0.0, 0.25, 0.5]
- an.ir.camera.is_affine(keys)[source]#
Whether the frame
keysshow 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 by1/(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:
- an.ir.camera.plane_dolly_scale(factor, dolly, *, plane='')[source]#
The scale a plane of parallax
factortakes ON TOP of the root’s zoom when the camera has travelleddolly(an#478): its growth over the character plane’s,(1 − dolly) / (1 − factor · dolly). Exactly1.0without a dolly or atfactor1. A dolly that reaches the plane (the camera at or past it) is aCameraError.>>> 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:
- an.ir.camera.sample_camera(keys, grid)[source]#
keysevaluated at every instant ofgrid(an#626), one key each with the grid’s easing: every field by the keys’ own easings, thezoommultiplied by the character plane’s dolly growth (exactly1without 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')]