# Level 1 property animation

[Canonical page](https://nothing.graphics/docs/format/spec/animation) · [Page source on GitHub](https://github.com/gridaco/nothing/blob/main/ncf/spec/animation.md)

Property ownership, key addresses, interpolation and fill behavior.



An inline track supplies a value for one property at a requested instant.
This chapter specifies its source representation, clock, and evaluation in
the Level 1 working draft.

## Authoring [#authoring]

Authoring intent lives physically beside the property definition. Every
authored appearance, geometry, or sound property is animatable unless its
definition names an exception. Its `animate` must be a direct child of the
owning element. The required `attributeName` selects a property of that
element. A shape owns its translation and opacity, a rectangle owns its width,
and a sequence placement owns its gain.
An animation declaration consumes no drawing or mixing slot. Changing a
shape's geometry preserves animation declared on the shape.

```xml
<scene frame-rate="24">
  <shape translate-x="0">
    <rect width="64" height="48" anchor-u="0" anchor-v="0"/>
    <fill><paint><solid color="#3366FFFF"/></paint></fill>
    <animate attributeName="translate-x" fill="freeze">
      <key frame="0" value="0" ease="hold"/>
      <key frame="12" value="40" ease="linear"/>
      <key frame="24" value="100"/>
    </animate>
  </shape>
</scene>
```

A timed scene declares its authored `frame-rate` in frames per second as a
positive integer or a ratio of positive integers, such as `24` or
`30000/1001`. Frame numbering starts at zero. Inline sequences inherit the
scene's rate. Each referenced timed scene declares its own rate.

## Key addresses [#key-addresses]

A key carries a `value` in the target property's grammar, units, and range,
and exactly one address.

| Address       | Meaning                                                                                                           | When the authored frame rate changes |
| ------------- | ----------------------------------------------------------------------------------------------------------------- | ------------------------------------ |
| `frame="12"`  | Integer frame index in the owning composition. At rate `R`, frame `n` occurs at `n / R` seconds.                  | Stays on frame 12.                   |
| `time="0.5s"` | Exact seconds, written as an integer, decimal, or integer fraction with a positive denominator and an `s` suffix. | Stays at half a second.              |

Writers preserve the choice of address. At 24 fps the two examples coincide.
At 30 fps frame 12 occurs at 0.4s. Changing the export rate only changes
which instants are sampled. Frame 1 at 30000/1001 fps is exactly 1001/30000s.
Resolve and compare times as rational values through every level of nesting.

An animation has at least two keys in strictly increasing resolved time.
Frame and time addresses can be mixed. Equal or reversed instants, including
after an authored rate edit, require a diagnostic identifying the keys.

## Evaluation [#evaluation]

Under Base evaluation each property reads its authored value or the default
defined for that property. A track still requires a valid base. If the
property requires an explicit attribute, supply it on the owner. For a sample
at time `t`, evaluate the owning composition directly at that instant.
Sampling preserves the authored tree and is independent of playback history.

The first key starts the animation. The time from first to last key is one
iteration. Each key except the last specifies the `ease` of its outgoing
segment. The last key carries only its address and value.

| Outgoing `ease` | Value on the segment                                                                                                                                                                                             |
| --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `hold`          | Use the left key's value until the right key's instant.                                                                                                                                                          |
| `linear`        | Pass the interval fraction directly to the type's interpolation rule. For finite scalars this gives `a + (b - a) × u`.                                                                                           |
| `spline`        | The key carries `keySplines="x1 y1 x2 y2"`, one SVG cubic Bézier tuple with coordinates in \[0, 1]. Use interval fraction `u` as the curve's x coordinate and its corresponding y as the interpolation fraction. |

Before the first key, the animation contributes nothing. At an interior
key's exact instant, its value takes effect. Optional `repeatCount` is a
positive integer and defaults to 1. At an interior repeat boundary the first
key takes effect again. At the final boundary, `fill="freeze"` retains the
last value and `fill="remove"` releases the property to the next contributing
animation or its base. Level 1 adopts SVG's attribute name, both values,
and its default of `remove`. On `<animate>`, `fill` governs the track's
contribution after its active interval. A key's outgoing ease governs the
segment leading to the next key.

For direct seeking, let `B` be the first key's time, `D` the difference
between last and first key times, and `N` the repeat count. The active
interval is `[B, B + N × D)`. Within it, look up the keys at
`q = B + ((t - B) mod D)`. Choose the surrounding keys such that
`t_left <= q < t_right` and pass `(q - t_left) / (t_right - t_left)` to
the left key's easing function. At or after `B + N × D`, use the track's
`fill` policy. A track keyed at frames 6 and 18 with two iterations starts
its second iteration at frame 18 and finishes at frame 30.

For simultaneous replacement effects on one property, the contributing
animation with the latest first-key time wins. The original first-key time
also determines priority during repeats and after a freeze. Equal starts
use later declaration order. When a higher-priority track releases the
property, sample the remaining tracks at the requested instant. Unknown
properties, invalid values, and invalid segment controls require a
diagnostic on the owning animation.

In the example, translation is 0 just before 0.5s, 40 at 0.5s, 70 at 0.75s,
and 100 from 1s onward.

## Property types and exceptions [#property-types-and-exceptions]

The property type supplies the interpolation rule.

* **Continuous values.** Finite scalars support hold, linear, and spline
  segments. This covers a gradient endpoint, a stop offset, and a stroke
  width, a trim endpoint, or a pivot coordinate using each property's units and range.
* **Colors.** `scene.background`, `solid.color`, and `stop.stop-color` support hold, linear,
  and spline. Decode each byte of `#RRGGBBAA` to a value from 0 to 1.
  Interpolate the three straight, encoded sRGB components and alpha
  independently with the same eased fraction. Preserve intermediate precision
  when passing the sampled color to a gradient or compositing operation.
  Premultiply only when computing its contribution. For transparent red
  to opaque blue, halfway gives straight RGBA (0.5, 0, 0.5, 0.5) and
  premultiplied RGBA (0.25, 0, 0.25, 0.5). A hold retains the left
  color, including RGB at zero alpha. This uses the same channel rule in
  time and across a [gradient ramp](https://nothing.graphics/docs/format/spec/graphics#paint). SVG supplies the precedent
  for keying color with an ordinary property track. [SVG color animation](https://www.w3.org/TR/SVG11/animate.html#AnimateColorElement)
  A transparent endpoint's RGB can therefore tint the middle of a fade.
  Key only opacity for a fade that keeps the same ink. Importing a CSS
  premultiplied transition with changing color and alpha requires sampling
  its curve or reporting the difference. [CSS interpolation with alpha](https://www.w3.org/TR/css-color-4/#interpolation-alpha)
* **Discrete values.** Use `ease="hold"` to switch between valid values at
  a key. Examples include a camera selector, a boolean operation, a font face request or
  weight, and the logical string `value` of a text or span with no child
  spans. Its base is the literal copy in that owner. [Text](https://nothing.graphics/docs/format/spec/text)
* **Point lists.** For a linear or spline segment, endpoints must contain the same number of `x,y` pairs. Interpolate each corresponding coordinate with the segment’s eased fraction. A held key can replace the whole list and change its length.
* **Path data.** Expand implicit repetitions, including the line segments after a move. Continuous endpoints must have the same sequence of commands and coordinate modes. Treat `Z` and `z` alike. Interpolate corresponding parameters numerically. For arc flags, interpolate 0 and 1 and treat any nonzero result as true. A hold can switch between any two valid paths. Report an incompatible continuous interval at the key. Sample the resulting geometry before resolving strokes, masks or attachments. [SVG 2 path interpolation](https://www.w3.org/TR/SVG2/paths.html#TheDProperty)
* **Other structured values.** A hold can switch between valid values. A continuous segment needs a specified interpolation rule.

Child insertion, removal, and reordering are edits to the document tree.
Scene dimensions (`width`, `height`) and `frame-rate` are document settings.
Attributes of `animate` and `key` define how the track is read. These are
outside property animation. Resource references
and placement timing (`begin`, `dur`, `source-start`) require separate
sampling rules and are outside this draft's animation targets. A declaration
targeting an excluded property or using an unsupported segment requires a
diagnostic on the animation.

The following properties illustrate the default and specify their base values.

| Owner and property                           | Value and effect                                                                                                                                                                                                                   |
| -------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `shape`, `group`, `sequence`                 | Translation and pivot coordinates default to 0, scale factors to 1, rotation in degrees to 0. [Transform order](https://nothing.graphics/docs/format/spec/spatial#local-to-parent)                                                 |
| `opacity` on the same three owners           | Scalar in \[0, 1] applied once to the composited picture. Base default 1.                                                                                                                                                          |
| `rect.width`                                 | Nonnegative width in local geometry units. The rectangle supplies its authored width.                                                                                                                                              |
| `anchor-u/v`, `offset-x/y` on boxed geometry | Independent scalar tracks on the primitive. Sample size, registration and offset before deriving the corner or center. [Defaults and units](https://nothing.graphics/docs/format/spec/boxed-geometry#size-registration-and-offset) |
| `sequence.gain`                              | Nonnegative linear amplitude multiplier on each channel before the placement is mixed into its parent. Base default 1.                                                                                                             |

## Picture, sound, and nesting [#picture-sound-and-nesting]

A sequence placement's own properties use its enclosing composition's time.
Its contents use `source-start + (t - begin)`. A referenced composition
interprets its frame keys at its authored rate after that mapping. Sample at
the resulting instant even when it falls between authored frames.
[Sequence rules](https://nothing.graphics/docs/format/spec/sequences)

```xml
<scene frame-rate="24">
  <sequence href="./voice.wav" begin="2s" dur="3s" source-start="10s" gain="0">
    <animate attributeName="gain" fill="freeze">
      <key time="2s" value="0" ease="linear"/>
      <key time="3s" value="1"/>
    </animate>
  </sequence>
</scene>
```

At parent time 2.5s the voice plays source time 10.5s at half amplitude.
Evaluate picture properties at each requested visual instant and audio gain
at each output sample instant. At 48 kHz the gain one sample after 2s is
exactly 1/48000 on this ramp. A key can address that sample directly as
`time="96001/48000s"`. A compound clip applies its gain once to its child
mix. When the placement ends at 5s it contributes silence.

External animation files and reusable animation definitions are deferred.
Further profiles can extend the property vocabulary, typed interpolation,
event timing, and additive composition. [Existing SVG animation profiles](https://github.com/gridaco/nothing/blob/main/docs/wg/feat-svg/animation.md)

## Design evidence [#design-evidence]

* **SVG and SMIL** define the timing interval, repetition, interpolation,
  post-interval fill, and priority of simultaneous effects. SVG also admits
  begin times derived from events. A deterministic production profile can
  reuse its clock-based math while selecting a smaller authoring surface.
  [SVG animation](https://www.w3.org/TR/SVG11/animate.html) · [SMIL Animation](https://www.w3.org/TR/2001/REC-smil-animation-20010904/)
* **After Effects** exposes temporal interpolation per property, including
  Hold, Linear, and Bézier. Its Audio Levels property is keyframeable and
  measured in decibels, with 0 dB representing unity. A straight line through
  dB values gives a different amplitude curve from a straight line through
  linear gain. Import must preserve that distinction. [Keyframe interpolation](https://helpx.adobe.com/after-effects/desktop/animate-in-after-effects/animation-keyframes/keyframe-interpolation.html) · [Audio Levels](https://helpx.adobe.com/my_en/after-effects/desktop/work-with-layers/layer-properties/layer-properties.html)
* **Blender** presents animated strip volume as a curve and reflects it in
  the displayed waveform. **Lottie** records typed property keyframes with
  frame times, hold flags, and easing tangents. Together these precedents
  distinguish an editable parameter curve from the media and from the
  author's choice of time display. [Blender strip properties](https://docs.blender.org/manual/en/latest/video_editing/edit/montage/strips/strip_properties.html) · [Lottie properties](https://lottie.github.io/lottie-spec/latest/single-page/)
* **Web Audio** specifies gain as multiplication of each channel's samples by
  a computed parameter and distinguishes audio-rate from control-rate
  automation. It provides a concrete reference for sample-rate gain evaluation.
  [Web Audio GainNode](https://www.w3.org/TR/webaudio-1.0/#GainNode)

### Decision on animating a gradient stop [#decision-on-animating-a-gradient-stop]

A stop owns its offset track. SVG defines an animatable offset on each stop.
Figma's plugin API likewise groups position and color in each stop of a
gradient paint. After Effects lets the artist edit individual stops while
keying the shape gradient's Colors property as a whole.
[SVG gradient stops](https://www.w3.org/TR/SVG2/pservers.html#GradientStops) · [Figma paint API](https://developers.figma.com/docs/plugins/api/Paint/) · [After Effects gradient editing](https://helpx.adobe.com/after-effects/desktop/drawing-painting-and-paths/shapes-and-shape-attributes/shape-attributes-paint-operations-path.html)

For the twelve-frame edit, the existing scalar track gives the editor one
source value to patch. A whole-gradient key would repeat the two stationary
stops and their colors. The middle stop stays identifiable by its owning
element throughout the edit. This case exercises strictly increasing offsets.
[Gradient animation cases](https://github.com/gridaco/nothing/blob/main/ncf/conformance/README.md#gradient-animation)
