Skip to content

Coordinates and anchors

A 160-pixel rectangle does not become 160% of the canvas. Vestra separates source geometry in pixels from placement in normalized parent coordinates. The anchor connects those spaces.

On a 640 by 360 canvas, position 0.25, 0.5 is pixel 160, 180. A 160 by 80 rectangle places its center there with anchor 0.5, 0.5, or its top-left there with anchor 0, 0.
The crosshair stays at pixel (160, 180). The anchor chooses which point of the rectangle attaches there.

Three different measurements

Value Space and units Example
Project(size=(640, 360)) Output canvas, pixels Width 640, height 360
Rectangle(width=160, height=80) Source-local geometry, pixels Size before placement transforms
position=(0.25, 0.5) Fraction of the parent canvas (160, 180) in that project
anchor=(0.5, 0.5) Fraction of the source's own extent The rectangle's center, (80, 40)
scale=(2, 1) Unitless multiplier Twice the width, same height
rotation=30 Clockwise degrees Rotation around the anchor

Coordinates start at the top-left: x increases rightward and y downward. Positions can extend outside [0, 1], which is useful for entrances and exits. Anchors must stay within [0, 1] on both axes. Scale components must be positive.

Place an edge instead of a center

These snippets build a new project, then change its rectangle placement:

from vestra import Project, Rectangle

project = Project(
    size=(640, 360),
    fps=30,
    duration=3,
)

panel = project.root.add(
    Rectangle(width=160, height=80, fill="#2563eb"),
    position=(0.25, 0.5),
)

The default anchor is the center, so the rectangle extends from (80, 140) to (240, 220) before antialiasing. Set its top-left corner on the same position:

panel.transform.anchor = (0, 0)

Its extent becomes (160, 180) to (320, 260). The position did not change; the point of the source attached to it did. Scaling and rotation keep that anchor at the placement position. Choosing a left-edge anchor is useful for a bar that grows to the right; choosing the center makes it grow in both directions.

Geometry belongs to the source

Rectangle widths, circle radii, line endpoints and polygon points describe source-local pixel geometry. A shape's geometry is static; animate its layer's transform to move, scale or rotate it. Stroke-only shapes use the same placement rules. See shape reference for each primitive's bounds and defaults, and animation for property tracks.

Images normally retain their intrinsic geometry; fit, cover and crop change how media uses the containing canvas. Text derives its bounds from layout. A Color source fills the containing canvas. These sources still use the layer transform to present that content.

Fit media to a canvas

Sizing changes the media geometry before the layer transform. Compare the same 160 × 80 pixel image centered in a 120 × 120 canvas:

A schematic source with left and right markers and a center circle is placed three ways: original keeps its 160 by 80 size and clips the sides, fit shows the whole source at 120 by 60, and cover fills the canvas with a 240 by 120 source whose sides are cropped.

Mode Adapted image What to notice
original 160 × 80 px Keeps the source size; the canvas clips its sides and leaves space above and below.
fit 120 × 60 px Shows the whole image with space above and below.
cover 240 × 120 px Fills the canvas and clips more of the sides.

The circle stays round in every panel: these modes preserve aspect ratio. Use explicit stretch sizing when distortion is intentional. Crop first chooses a source region; sizing adapts that region, then the layer's transform places it.

Each group has a parent and a local canvas

A child's normalized position uses its group's local canvas. The group's own placement uses the parent's canvas, and its transform acts on the completed children. Follow the root and group coordinate diagram to see the normalized positions used by a group and its child.

Continue with groups and nesting for local bounds and clipping, or use the source guide to place media and text.